Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about overriding  RSS feed

 
Shane Jensen
Ranch Hand
Posts: 113
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

From, question 7:



Possible answers:
A) cougar c f
B) feline cougar c c
C) feline cougar c f
D) Compilation fails.

The answer is B according to the document, but I thought it's A. I have no idea how it's possible that 'feline' is printed first. I have been breaking my head over this for a while. Any suggestions?

Thanks in advance!
 
Shane Jensen
Ranch Hand
Posts: 113
7
 
Dominique Ubersfeld
Greenhorn
Posts: 7
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the general rule that applies to your example:

If the subclass constructor does not specify which superclass constructor to invoke then the compiler will automatically call the accessible no-args constructor in the superclass. In your example Feline() is the accessible no-args constructor.
 
Shane Jensen
Ranch Hand
Posts: 113
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dominique Ubersfeld wrote:Here is the general rule that applies to your example:

If the subclass constructor does not specify which superclass constructor to invoke then the compiler will automatically call the accessible no-args constructor in the superclass. In your example Feline() is the accessible no-args constructor.

Right, of course! Thank you so much
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!