• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access Modifier Doubt

 
Sachin N Naik
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Sachin N Naik
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lucius, you are right. Actually i was under impression that book is saying that protected members can be accessed without inheritance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic