Skip to content
Sharp

Modern Java · interview question

How do you write a multiline string in Java using text blocks?

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

Correct answer

A. By enclosing the string in triple double quotes.

Why

Java text blocks are defined using triple double quotes, allowing developers to write multiline strings without concatenation or escape sequences. This makes the code more readable and easier to maintain.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →