• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Access Modifier Doubt

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic