Taken from Sun e-Practice for
JAVA 5
SCJP Mock Exam :
Which is true?
A. The output is 344.
B. Compilation fails due to an error at line 5.
C. Compilation fails due to an error at line 11.
D. At line 8, an object is eligible for garbage collection
Answer : D (Because the object lifeline of tale only exist within the if statment)
What's surprising me is that why wasnt the output 344?
1. A value of 343 was passed into the go() method.
2. t++; un-wraps the Long object, increments, and returns 344?
3. The value of 344 is assigned to variable story.
4. System.out.print value out, but the value was actually 343.
Why is that so? I always believed that incrementing ++ wrapper objects adds one to the value.
Please enlighten me !