Skip to content
Sharp

Modern Java · interview question

Which of the following is a valid way to define a text block in Java?

Multiple choiceEasychapter-12-curatedpremiummodern-javatext-blocks
Choose one answer
Answer and explanation

Correct answer

D. String json = """ { "name": "Alice" } """;

Why

Text blocks in Java are defined using triple double quotes ("""). This allows for multiline strings without the need for additional concatenation or special characters.

Test yourself on Modern Java

A free test with instant, explained results. No account needed.

Start free test
All Modern Java questions →