Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Protected Method

 
Paulo Aquino
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Another class extends the class above.




Compiling this code gives me this error:
testMethod() has protected access in com.scjp.protect.ProtectedMethod

Why is this so? But when I changed my code in the callMe() method to



It doesn't compile of any error.I thought when you inherit a particular class and its members are protected you can instantiate it and operate on it.
 
Paulo Aquino
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already got the answer, I can only use inherited members through inheritance and not through reference calls.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for sharing what you learned, Paulo!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic