🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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);
    }
}
  1. A.ab
  2. B.c
  3. C.abc
  4. 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 →