Question

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

Option 1 : -128 / -128

Advertisement

Detailed Solution

सही उत्तर -128 / -128 है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the value of `b` after this Java code? `byte b = 127; b++;` / इस Java कोड के बाद `b` का मान क्या होगा? `byte b = 127; b++;`

1.
-128 / -128
2.
128 / 128
3.
Compilation error — possible loss of precision / कंपाइलेशन त्रुटि — precision की संभावित हानि
4.
0 / 0

Correct Answer: -128 / -128

`byte` is an 8-bit signed two's-complement type, so incrementing the maximum 127 wraps around to -128. The trap is expecting 128, which a signed byte cannot represent, or a compile error — note `b++` compiles because compound increment includes an implicit cast. / `byte` 8-बिट signed two's-complement प्रकार है, अतः अधिकतम 127 को बढ़ाने पर -128 पर wrap होता है। जाल 128 की अपेक्षा करना है, जिसे signed byte दर्शा नहीं सकता, या compile error मानना है — ध्यान रहे `b++` कंपाइल होता है क्योंकि इसमें implicit cast निहित है।

Downloaded from PrepSnap (prepsnap.in)