Page 1 of 1

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

Posted: Mon Sep 02, 2013 12:13 pm
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.

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

Posted: Mon Sep 02, 2013 12:23 pm
by admin
Well, since the code will not even compile, that option is not really applicable.

HTH,
Paul.

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

Posted: Tue Dec 08, 2015 1:19 pm
by dannysantos1985
I thought that an instance field got initialized automatically. This doesn't apply in this case?

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

Posted: Tue Dec 08, 2015 8:03 pm
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.

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

Posted: Mon Oct 30, 2017 3:11 am
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?

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

Posted: Mon Oct 30, 2017 3:57 am
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.