Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 1 : false true

Advertisement

Detailed Solution

सही उत्तर false true है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Java program? String s1 = "Java"; String s2 = new String("Java"); System.out.print((s1 == s2) + " " + s1.equals(s2)); / निम्नलिखित Java प्रोग्राम का आउटपुट क्या है?

1.
false true
2.
true true
3.
true false
4.
false false

Correct Answer: false true

The == operator compares object references: s1 refers to the string-pool literal while s2 is a separate heap object, so it is false. The equals() method compares contents, which are identical, so it is true. / == ऑपरेटर ऑब्जेक्ट संदर्भों की तुलना करता है: s1 स्ट्रिंग-पूल लिटरल को संदर्भित करता है जबकि s2 एक अलग हीप ऑब्जेक्ट है, इसलिए यह false है। equals() मेथड सामग्री की तुलना करता है, जो समान है, इसलिए यह true है।

Downloaded from PrepSnap (prepsnap.in)