This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic