File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Access Modifier Doubt 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 "Access Modifier Doubt" Watch "Access Modifier Doubt" New topic

Access Modifier Doubt

Sachin N Naik

Joined: Jun 09, 2006
Posts: 11
Hello Friends,

I'm studying K & B book for SCJP 1.4. I have a doubt regarding Access Modifiers in Java. In K & B book a Table 2.1 is given on page 83.
In this table second row says that "You can access a protected member of a from any class in same package". Can you please explain the meaning of this.
I think this doesnt work because you need to extend that class even if its in the same package.

Sachin Naik
Lukas Stephienn
Ranch Hand

Joined: Dec 23, 2005
Posts: 60
No, protected in java works diffrently from c++.
K&B are correct.
Protected can be accesses within a package or from subclasses (but only through inheritance).

SCJP 5.0 (91%), SCBCD 1.3 (94%), SCWCD 1.4 (88%)
Sachin N Naik

Joined: Jun 09, 2006
Posts: 11
Thanks Lucius, you are right. Actually i was under impression that book is saying that protected members can be accessed without inheritance.
I agree. Here's the link:
subject: Access Modifier Doubt
It's not a secret anymore!