Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance - Protected Method  RSS feed

 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why am I not able to invoke a protected method from within a subclass?

and

[ April 27, 2007: Message edited by: Sasha Ruehmkorf ]
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K&B:

But what does it mean for a subclass-outside-the-package to have access to a superclass (parent) member? It means the subclass inherits the member. It does not, however, mean the subclass-outside-the-package can access the member using a reference to an instance of the superclass. In other words, protected = inheritance. Protected does not mean that the subclass can treat the protected superclass member as though it were public.


Ok, got it :-)
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can invoke a superclass method from inside an instance of a subclass. Your static method does not form part of the instance.
Try:
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the hint.
Still some strange things occur with the protected-modifier but I think I understand enough to answer the questions regarding "protected" in the exam and that should do it for the moment.

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sasha Ruehmkorf:
[/QB]


In fact, you can be sure that every Father has such a method. But you simply don't have access to it, other than through the "this" reference.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!