ProgrammingVery hardTCS NQT · Wipro NLTH

What is printed?

What is printed?
String a = "ja" + "va";
String b = "java";
String c = "ja";
String d = c + "va";
System.out.print((a == b) + "," + (d == b));
  1. A. true,false
  2. B. true,true
  3. C. false,false
  4. D. false,true

Correct answer: A. true,false

"ja" + "va" is a compile-time constant and is interned, but c + "va" is built at run time as a new String.

More OOP with C++ and Java questions

Exams that ask this topic