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.
About Question enthuware.ocajp.i.v7.2.906 :
Moderator: admin
-
- Posts: 2
- Joined: Tue Aug 27, 2013 11:54 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.906 :
Well, since the code will not even compile, that option is not really applicable.
HTH,
Paul.
HTH,
Paul.
-
- Posts: 12
- Joined: Tue Nov 24, 2015 4:34 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.906 :
I thought that an instance field got initialized automatically. This doesn't apply in this case?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.906 :
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.
HTH,
Paul.
-
- Posts: 8
- Joined: Wed Oct 25, 2017 2:53 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.906 :
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?
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?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.906 :
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.
If the code doesn't compile, whether the ANGLE will or will not be set to 90 is irrelevant.
Who is online
Users browsing this forum: No registered users and 12 guests