About Question enthuware.ocajp.i.v7.2.1181 :
Moderators: Site Manager, fjwalraven
-
- Posts: 31
- Joined: Thu Feb 19, 2015 8:25 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1181 :
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
!!!
!!!
-
- Site Admin
- Posts: 10090
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1181 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1181 :
There is no mention but max() is overriden?
-
- Site Admin
- Posts: 10090
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1181 :
No, why do you think it might be?
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1181 :
Method in the child class has the same signature as the method in the parent class.
-
- Site Admin
- Posts: 10090
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1181 :
You are right. I mistakenly opened another question.
Yes, the method max is being overridden in B and then again in C.
Paul.
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.
-
- Posts: 3
- Joined: Mon Aug 27, 2018 2:15 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1181 :
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
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
-
- Site Admin
- Posts: 10090
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1181 :
The explanation has been updated to make it clear.
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 12 guests