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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
UmairAhmed
Posts: 9
Joined: Mon Apr 28, 2014 9:16 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Eugeny
Posts: 3
Joined: Mon Jun 08, 2015 3:28 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

The question is talking about the printed output. 10.0 in the output is not exactly same as 10.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests