| Author |
Inheritance - Protected Method
|
Sasha Ruehmkorf
Ranch Hand
Joined: Mar 29, 2007
Posts: 115
|
|
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
Joined: Mar 29, 2007
Posts: 115
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
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
Joined: Mar 29, 2007
Posts: 115
|
|
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
Joined: Jul 11, 2001
Posts: 14112
|
|
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.
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
|
|
subject: Inheritance - Protected Method
|
|
|