ProgrammingVery hardGATE CS · TCS Digital · Advanced

What is printed?

What is printed?
Long l = 127L;
Integer i = 127;
System.out.print(l.equals(i) + " " + l.equals(127L) + " "
               + (l == 127) + " " + l.equals(127));
  1. A. false false true false
  2. B. true true true true
  3. C. false true true false
  4. D. false true true true

Correct answer: C. false true true false

Long.equals needs a Long argument, so the Integer i and the boxed int literal 127 both give false; 127L boxes to Long (true); l == 127 unboxes l and compares numerically (true).

More OOP with C++ and Java questions

Exams that ask this topic