Question 1
What does this print?
public class Main {
public static void main(String[] args) {
String s = """
a\s
b""";
System.out.print(s.length());
}
}A. 4Correct answer
After the 12-space incidental indentation is stripped the lines are a\s and b; escape processing runs after stripping, so \s becomes a real space that survives. The value is a, space, newline, b — length 4.
B. 2
Treats \s like the line-continuation escape <newline>, which would delete the newline and add nothing; but \s adds a real space instead.
C. 3
Forgets the single space contributed by the \s escape.
D. 5
Counts the backslash and s as two literal characters, but \s is a single escape producing one space.
Explanation
Text-block processing strips incidental white space before it processes escape sequences, so escapes always act on the already-trimmed content. The \s escape produces a single protected space that survives stripping, unlike a bare trailing backslash which merely deletes its line terminator and adds nothing. Here the value consists of the first line's character, a protected space, a newline, and the second line's character — four characters in all.