Skip to content
CodeKruPro

String pool, constants and intern()

QuizMediumJava onlyAsked in: Capgemini, Infosys

What does this print?

String s1 = "ab";
String s2 = "a" + "b";
String part = "a";
String s3 = part + "b";
System.out.println((s1 == s2) + " " + (s1 == s3) + " " + (s1 == s3.intern()));
  • true false true
  • false false true
  • true true true
  • true false false

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in