tg-me.com/topJavaQuizExplain/205
Last Update:
What is the output of the code snippet?
❌ A. true true true true
❌ B. false false false false
❌ C. false true false true
✅ D. true true false true
❌ E. false true true true
❌ F. true false false true
❌ G. The code does not compile
❌ H. None of the above
Explanation:
On line 15, we have a compile-time constant that automatically gets placed in the string pool as "rat1" . On line 16, we have a more complicated expression that is also a compiletime constant. Therefore, first and second share the same string pool reference. This makes line 18 and 19 print true. On line 17, we have a String constructor. This means we no longer have a compile-time constant, and third does not point to a reference in the string pool. Therefore, line 20 prints false . On line 21, the intern() call looks in the string pool. Java notices that first points to the same String and prints true.
BY Explanations “Top Java Quiz Questions”
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Share with your friend now:
tg-me.com/topJavaQuizExplain/205