Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes protected  memeber Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "protected  memeber" Watch "protected  memeber" New topic
Author

protected memeber

Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
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?


Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
soumya ravindranath
Ranch Hand

Joined: Jan 26, 2001
Posts: 300
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 ]
 
Consider Paul's rocket mass heater.
 
subject: protected memeber