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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
alexz1011
Posts: 4
Joined: Sun Mar 29, 2015 7:20 am
Contact:

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

Post 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.

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

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

Post by admin »

TesClass has appropriate imports.
If you like our products and services, please help us by posting your review here.

alexz1011
Posts: 4
Joined: Sun Mar 29, 2015 7:20 am
Contact:

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

Post by alexz1011 »

TestClass has correct imports, but the member variable "location" hasa default access modifier, so "m.location" in TestClass is an error?

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

alexz1011
Posts: 4
Joined: Sun Mar 29, 2015 7:20 am
Contact:

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

Post by alexz1011 »

Ah, I see! Gotcha :)

rafaparche
Posts: 5
Joined: Tue Apr 14, 2015 9:32 am
Contact:

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

Post 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!

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

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

Post by admin »

Inheritance applies to instance members only.
If you like our products and services, please help us by posting your review here.

scranen
Posts: 12
Joined: Thu May 07, 2015 8:55 am
Contact:

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

Post 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.

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

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

Post 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?
If you like our products and services, please help us by posting your review here.

ha12345
Posts: 2
Joined: Fri Jun 26, 2015 2:35 pm
Contact:

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

Post 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?

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

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

Post by admin »

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.

Mushfiq Mammadov
Posts: 32
Joined: Fri Oct 16, 2015 4:33 am
Contact:

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

Post 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 :)

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

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

Post by admin »

Fixed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests