Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

protected memeber

 
Raghu Shree
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In k&b book page no 80.
Once the subclass-outside-the package inherits the protected member, that member becomes private to any code outside the class.

I am confused this point. Could any one explain me with one example?
 
soumya ravindranath
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raghu,

I think it's something like this -





Compiling this gives an error because the class ProtTest cannot access baseVar as pc.baseVar. baseVar is inherited by ProtChild, but outside of the class it is not visible. If you change the println as
System.out.println( pc.method() );
then, there will be no error.

- Soumya.
[ May 10, 2005: Message edited by: soumya ravindranath ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic