← Quiz: Java Strings: all 10 questions
Quiz: Java Strings · Question 7 of 10
What does this print? (code)
What does this print?
public class Main {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("ab");
StringBuilder t = sb;
t.append("c");
System.out.println(sb);
}
}
- A.ab
- B.c
- C.abc
- D.abab
Answer & explanation
Correct answer: abc
StringBuilder is mutable, and sb and t refer to the same object, so the change is visible through both.
Can you get the rest right without peeking?
Take the timed Quiz: Java Strings quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →