🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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));
    }
}
  1. A.true true
  2. B.true false
  3. C.false false
  4. 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 →