Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1081 :

Posted: Mon May 19, 2014 7:32 pm
by UmairAhmed
Hi,

Can you please explain how & what exactly is happening in option 1 of this answer.
Option 1:
Object t = new Integer(106);
     int k = ((Integer) t).intValue()/10;
    System.out.println(k);
To my understanding, reference variable t has been assigned an object holding value of 106.
Then integer variable k is assigned a value of : value acquired by variable t which is casted into integer (i.e. 106), then method intValue() is also returning the same value(i.e. 106) and it is then divided by 10.

And why we need intValue method here. Though the code is running fine without even using intValue() method.

Re: About Question enthuware.ocajp.i.v7.2.1081 :

Posted: Mon May 19, 2014 9:02 pm
by admin
Your understanding is correct.
There is no need for calling intValue(). It is there just to make you aware of intValue and to make it more interesting.
HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1081 :

Posted: Wed Jul 01, 2015 2:34 pm
by Eugeny
Hi,
It is not very clear what does "exactly 10" mean. From the mathematical point of view 10.0 is also exactly 10.
In this case the option 3 is also valid.

Re: About Question enthuware.ocajp.i.v7.2.1081 :

Posted: Wed Jul 01, 2015 9:11 pm
by admin
The question is talking about the printed output. 10.0 in the output is not exactly same as 10.

HTH,
Paul.