← Quiz: Java Interview Questions: all 10 questions
Quiz: Java Interview Questions · Question 2 of 10
What does this print? (code)
What does this print?
public class Main {
public static void main(String[] args) {
String s = "Hi";
StringBuilder sb = new StringBuilder("Hi");
System.out.println(s.equals(sb.toString()) + " " + s.equals(sb));
}
}
- A.true true
- B.true false
- C.false false
- D.false true
Answer & explanation
Correct answer: true false
equals compares content with another String. sb itself is a StringBuilder, not a String, so the second is false.
Can you get the rest right without peeking?
Take the timed Quiz: Java Interview Questions quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →