Page 1 of 1

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

Posted: Sun Mar 29, 2015 7:23 am
by alexz1011
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.

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

Posted: Sun Mar 29, 2015 8:45 am
by admin
TesClass has appropriate imports.

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

Posted: Sun Mar 29, 2015 4:31 pm
by alexz1011
TestClass has correct imports, but the member variable "location" hasa default access modifier, so "m.location" in TestClass is an error?

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

Posted: Sun Mar 29, 2015 9:57 pm
by admin
Gotcha :D
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.

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

Posted: Mon Mar 30, 2015 6:15 am
by alexz1011
Ah, I see! Gotcha :)

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

Posted: Tue Apr 14, 2015 10:29 am
by rafaparche
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!

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

Posted: Tue Apr 14, 2015 2:55 pm
by admin
Inheritance applies to instance members only.

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

Posted: Mon May 18, 2015 4:05 am
by scranen
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.

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

Posted: Mon May 18, 2015 5:22 am
by admin
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.
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.
You cannot expect every question to specify that jdk is installed and javac is in path, can you?

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

Posted: Fri Jun 26, 2015 2:38 pm
by ha12345
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?

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

Posted: Sat Jun 27, 2015 9:40 am
by admin
Yes, it is ok. You might want to try compiling and running it.

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

Posted: Tue Oct 27, 2015 8:41 am
by Mushfiq Mammadov
It would be good to add "public" into the second sentence. And m.moveBank(20) should be m.moveBack(20)
Image

P.S. By the way, it is a very good question :)

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

Posted: Tue Oct 27, 2015 9:52 pm
by admin
Fixed.
thank you for your feedback!