About Question enthuware.ocajp.i.v7.2.1403 :
Moderators: Site Manager, fjwalraven
-
- Posts: 4
- Joined: Sun Mar 29, 2015 7:20 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1403 :
I would have thought the answer is "TestClass.java will not compile", because TestClass.java is in a different package than Donkey.java.
Therefore "System.out.println(m.location)" in TestClass.java causes a compilation error.
Therefore "System.out.println(m.location)" in TestClass.java causes a compilation error.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
TesClass has appropriate imports.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Sun Mar 29, 2015 7:20 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
TestClass has correct imports, but the member variable "location" hasa default access modifier, so "m.location" in TestClass is an error?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
Gotcha
m.location does not have default access modifier. Observe that the type of m is Movable. Not Donkey. Accessibility check is done by the compiler based on the type of the variable and not on the type of object referred to by the variable.
m.location does not have default access modifier. Observe that the type of m is Movable. Not Donkey. Accessibility check is done by the compiler based on the type of the variable and not on the type of object referred to by the variable.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Sun Mar 29, 2015 7:20 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
Ah, I see! Gotcha
-
- Posts: 5
- Joined: Tue Apr 14, 2015 9:32 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
Hi!
Interface fields are static final so can they be shadowed or they are inherited? Because if they are inherited then my doubt it's why don't throw a error when Donkey is instantiated since location got a new value?
Thanks!
Interface fields are static final so can they be shadowed or they are inherited? Because if they are inherited then my doubt it's why don't throw a error when Donkey is instantiated since location got a new value?
Thanks!
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
Inheritance applies to instance members only.
If you like our products and services, please help us by posting your review here.
-
- Posts: 12
- Joined: Thu May 07, 2015 8:55 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
The question should probably mention something along the lines of "assume the files are placed in the right directory structure and are compiled using the appropriate classpath", otherwise both Donkey.java and TestClass.java will not compile.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
Anything that is not specified in the question should be assumed to be in order. This practice is followed by the real exam as well.scranen wrote:The question should probably mention something along the lines of "assume the files are placed in the right directory structure and are compiled using the appropriate classpath", otherwise both Donkey.java and TestClass.java will not compile.
You cannot expect every question to specify that jdk is installed and javac is in path, can you?
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Fri Jun 26, 2015 2:35 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
int location = 0 in the interface is final. Not possible to change the value. In the class Donkey there is a value change with int location = 200. Is this ok because the variable location is declared in class Donkey and had no relation with the interface?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
Yes, it is ok. You might want to try compiling and running it.
If you like our products and services, please help us by posting your review here.
-
- Posts: 32
- Joined: Fri Oct 16, 2015 4:33 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
It would be good to add "public" into the second sentence. And m.moveBank(20) should be m.moveBack(20)
P.S. By the way, it is a very good question
P.S. By the way, it is a very good question
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1403 :
Fixed.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 27 guests