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

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

Moderator: admin

Post Reply
loozak84
Posts: 2
Joined: Tue Aug 27, 2013 11:54 am
Contact:

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

Post by loozak84 »

Hi,

Is statement from option a) (the value of ANGLE will not be set to 90 by the setAngle method.) correct?
For me it's like there should be two correct answers; a and d.

M.

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

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

Post by admin »

Well, since the code will not even compile, that option is not really applicable.

HTH,
Paul.

dannysantos1985
Posts: 12
Joined: Tue Nov 24, 2015 4:34 pm
Contact:

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

Post by dannysantos1985 »

I thought that an instance field got initialized automatically. This doesn't apply in this case?

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

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

Post by admin »

An instance field does get initialized automatically but only if it is not declared final. If it is declared final, you have to initialize it explicitly. You can do that at the time of declaration, e.g. private final double ANGLE = 90; or in each constructor of the class, or in an instance initializer.

HTH,
Paul.

bortnikov_sa@mail.ru
Posts: 8
Joined: Wed Oct 25, 2017 2:53 am
Contact:

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

Post by bortnikov_sa@mail.ru »

Hi,
If you'll try to compile code of this example, you will get:
"error: cannot assign a value to final variable ANGLE
public void setAngle(double a){ ANGLE = a; }
^
1 error"
This code did not compile becose of option a) "the value of ANGLE will not be set to 90 by the setAngle method".
Why this opion is incorrect?

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

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

Post by admin »

Since only one option is to be selected, you have to select the best option and as you observed, the given code will not compile, that is why the option that says "The code will not compile." is the correct option.

If the code doesn't compile, whether the ANGLE will or will not be set to 90 is irrelevant.

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests