Consider the following code segment. Which choice shows the output?
System.out.println("A\n\"B\"\\C");
A\n\"B\"\\CA"B"\CAB C\n starts a new line and the quotation marks and backslash appear.
Explanation
An escape sequence begins with a backslash and gives the next character a special meaning. It is written with two source-code characters but represents one character in the resulting text, so the printed result is shorter than the literal.
- A is not correct: this choice repeats the source characters instead of the resulting text, but each escape sequence is two source-code characters that represent one character.
- C is not correct: the quotation marks and the backslash are dropped here, while
\"places a quotation mark and\\places one backslash in the text. - D is not correct: the code compiles, because each backslash begins one of the valid escape sequences rather than an invalid one.