🎙 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 5 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        String s = "abc";
        s.concat("def");
        System.out.println(s);
    }
}
  1. A.abcdef
  2. B.abc
  3. C.def
  4. D.Error
Answer & explanation

Correct answer: abc

concat returns a new string, which is ignored; s still refers to "abc".

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 →