aspose file tools
The moose likes Beginning Java and the fly likes Inheritance - Protected Method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Inheritance - Protected Method" Watch "Inheritance - Protected Method" New topic
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
    
    4
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Inheritance - Protected Method
 
Similar Threads
Protected variable - why not accessible in subclass
access specifier protected
Package Problem...
Reflection access rules
doubt in protected access