Computer Applications

The output of the below statement is:

System.out.println("I said, \"It\'s wise to obey elders.\"");

  1. I said, 'It is wise to obey elders.'
  2. I said, "It's wise to obey elders."
  3. I said, It's wise to elders.
  4. "'It's wise to obey elders.'"

Java

Values & Data Types Java

5 Likes

Answer

I said, "It's wise to obey elders."

Reason — In Java, the backslash \ is used as an escape character. The statement uses escape sequences:

  • \" to include double quotes inside a string.
  • \' to include a single quote inside a string.

So the output preserves both the double quotes around "It's wise to obey elders." and the apostrophe in It's.

Hence, the output is: I said, "It's wise to obey elders."

Answered By

2 Likes


Related Questions