Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "protected  memeber" Watch "protected  memeber" New topic

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="" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="" 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 ]
I agree. Here's the link:
subject: protected memeber
jQuery in Action, 3rd edition