🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Immutability and Value Objects: all 10 questions

Quiz: Immutability and Value Objects · Question 1 of 10

What does this print? (code)

What does this print?

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

Correct answer: java

Strings are immutable; both results were thrown away, so s is unchanged.

Can you get the rest right without peeking?

Take the timed Quiz: Immutability and Value Objects quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →