• 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

Protected Access Modifier

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends Iam studying SCJP book...
Now this protected modifier section is killing and confusing me... Ok let me start...
I have a class Parent in one package,the Child class in another package inherits the protected member... upto here its working fine...
Now SCJP books reads that.... "what if another class in same package as a Child class can access the protected member of Parent through Child by instantiating the Child class...?
The answer given in the book was straight forward i.e,no.. They further told that the protected member accessed by subclass will behave private to all other class from here onwards....
For example:A class Neighbour in the same package as that of Child",can access the protected member of Parent through Child "...
SCJP book is atleast saying no but when i try to do it practically the answer is quiet different... Any suggestion where y understanding is going wrong...?.
I have written down the code here which is working fine but voilating what My SCJP book is telling...
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try c.hmmm();? It says that accessing the protected method other than through inheritance in a different package is not possible. But in the example you are accessing the protected method in the instance of Child class, so you are still in the context of the Child class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic