This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Access Modifier Doubt" Watch "Access Modifier Doubt" New topic
Author

Access Modifier Doubt

Sachin N Naik
Greenhorn

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.

Thanks,
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
Greenhorn

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Access Modifier Doubt
 
Similar Threads
Doubt
Doubt
doubt
Package Doubt :(
Doubt in overriding