Page 1 of 1

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

Posted: Sat Jun 06, 2015 2:28 pm
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
!!!

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

Posted: Sat Jun 06, 2015 9:29 pm
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.

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

Posted: Sat May 26, 2018 9:45 am
by flex567
There is no mention but max() is overriden?

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

Posted: Mon May 28, 2018 9:14 pm
by admin
No, why do you think it might be?

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

Posted: Tue May 29, 2018 1:04 am
by flex567
Method in the child class has the same signature as the method in the parent class.

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

Posted: Tue May 29, 2018 1:35 am
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.

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

Posted: Mon Aug 27, 2018 2:25 am
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

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

Posted: Mon Aug 27, 2018 3:29 am
by admin
The explanation has been updated to make it clear.

thank you for your feedback!