• Post Reply Bookmark Topic Watch Topic
  • New Topic

Protected Access Modifier  RSS feed

 
rizwana mujawar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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...
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!