Question

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

Option 1 : true false

Advertisement

Detailed Solution

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

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Java code? Integer a = 127, b = 127; Integer c = 128, d = 128; System.out.println((a==b) + " " + (c==d)); / निम्नलिखित Java कोड का आउटपुट क्या है? Integer a = 127, b = 127; Integer c = 128, d = 128; System.out.println((a==b) + " " + (c==d));

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

Correct Answer: true false

The == operator compares object references. Java caches Integer objects in the range -128 to 127, so a and b refer to the same cached object (true), while 128 is outside the cache, so c and d are distinct objects (false). / == ऑपरेटर ऑब्जेक्ट संदर्भों की तुलना करता है। Java -128 से 127 रेंज के Integer ऑब्जेक्ट कैश करता है, अतः a और b एक ही कैश्ड ऑब्जेक्ट को संदर्भित करते हैं (true), जबकि 128 कैश के बाहर है, अतः c और d भिन्न ऑब्जेक्ट हैं (false)।

Downloaded from PrepSnap (prepsnap.in)