File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 24199

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.
I agree. Here's the link:
subject: Inheritance of protected members
It's not a secret anymore!