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

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
Sergiy Romankov
Posts: 31
Joined: Thu Feb 19, 2015 8:25 am
Contact:

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

Post by Sergiy Romankov »

Error in this question, if you change the order and first declare classes A,B,C then is all correct, but now it is not 80, but compile time Error
!!!

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

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

Post by admin »

No, the question is fine. Please make sure you use command line to compile and run. Order of declaration of classes doesn't matter.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

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

Post by flex567 »

There is no mention but max() is overriden?

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

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

Post by admin »

No, why do you think it might be?
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

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

Post by flex567 »

Method in the child class has the same signature as the method in the parent class.

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

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

Post by admin »

You are right. I mistakenly opened another question.
Yes, the method max is being overridden in B and then again in C.

Paul.
If you like our products and services, please help us by posting your review here.

sebaskoot
Posts: 3
Joined: Mon Aug 27, 2018 2:15 am
Contact:

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

Post by sebaskoot »

Thanks Paul for your answer. I was confused because in the evaluation of the question override is not mentioned.

The text of the current explanation is:
When the program is run, the main() method will call the max() method in C with parameters 10 and 20 because the actual object referenced by 'c' is of class C. This method will call the max() method in B with the parameters 20 and 40. The max() method in B will in turn call the max() method in A with the parameters 20 and 40. The max() method in A will return 40 to the max() method in B. The max() method in B will return 80 to the max() method in C. And finally the max() of C will return 80 in main() which will be printed out.

The first sentence in this explanation is very confusing for me.

I would suggest to change it to:
The methods and fields of B are used because it is a B-type reference. But since C overrides the B method correctly the C method is used.

Do you agree with this?

Thanks, Sebastiaan

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

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

Post by admin »

The explanation has been updated to make it clear.

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: Bing [Bot] and 31 guests