Discussion :: Java.lang Class - Finding the output (Q.No.2)
|Kawish said: (Apr 26, 2015)|
|I don't, understand x equal y concept and how the answer will be 10?|
|Bill said: (May 11, 2015)|
Result = 0.
/*Only line 15 is correct*/
Result = Result+10;
Then result = 10.
|Rahul said: (Nov 21, 2015)|
|How can it possible?|
|Zakir said: (Mar 7, 2016)|
|Anybody can explain this question.|
|Lena said: (May 12, 2016)|
|Just try some interesting addition: for values between -128 and 127, if used without "new" operator like this:
Long i = 42L;
Long i2 =42L;
The result of (i==i2) will be true because Java caches objects instances from the range -128 to 127.
But in the case with new operator Java will always create different objects so == will return false even in this range.
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.