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

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        String a = "hi";
        String b = new String("hi");
        System.out.println(a == b);
    }
}
  1. A.true
  2. B.false
  3. C.hi
  4. D.Error
Answer & explanation

Correct answer: false

new String creates a separate object, so == (reference comparison) is false.

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 →