go to previous page   go to home page   go to next page
String test = "Quoth the raven, "Nevermore."";

Answer:

No, that will not work. The quote marks around "Nevermore." will confuse the compiler.


Escaping Special Characters in Strings

Quote marks are used in Java to start and end strings. To indicate to the compiler that you want the quote mark itself, escape the quote mark with a backslash. The following will work correctly:

String test = "Quoth the raven, \"Nevermore.\"";

If you want a backslash in a String, use two backslashes in the code:

String test = "This \\ is a backslash.";

QUESTION 10:

What is the output of the following fragment?

String test = "\"This is a backslash \\\", she said.";

System.out.print( test );