← 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);
}
}
- A.true
- B.false
- C.hi
- 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 →