Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance of protected members

 
Kiran Kate
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
praveen Shangunathan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic