This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Inheritance of protected members Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance of protected members" Watch "Inheritance of protected members" New topic

Inheritance of protected members

Kiran Kate

Joined: Sep 26, 2005
Posts: 2
Are the protected members of a class inherited by objects of subclasses outside the package of the class?
if yes, why do we need the subclass object reference to access them?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Yes, protected members are inherited by all subclasses. I don't understand your second question, though -- perhaps you could use an example to explain it.

[Jess in Action][AskingGoodQuestions]
praveen Shangunathan
Ranch Hand

Joined: Sep 06, 2005
Posts: 65
You can inherit protected members outside the package by subclasses.

BUT to access protected members from another package you have to
1) get it by inheritence ( NOT by reference to the superclass) OR
2) by creating a reference to the subclass, and calling the protected member through this subclass reference.

hope this helps.
subject: Inheritance of protected members
Similar Threads
Why can't a class be protected?
What Inheritance Actually Do
access modifier
Protected members inheritance
confuse about protected and static