Multiple choice

Which of the following are valid Java String literals?

  1. ""Hello", she said"

  2. "Falling\n\tleaves"

  3. "Can't tell"

  4. If he'll just listen once

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

A valid Java String literal must be enclosed in double quotes. Option B is valid because it starts and ends with double quotes and contains valid escape sequences (\n for newline and \t for tab). Option A has unescaped nested quotes, and Option C has a backslash outside the quotes.