*
The moose likes Beginning Java and the fly likes Protected Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Protected Method" Watch "Protected Method" New topic
Author

Protected Method

Paulo Aquino
Ranch Hand

Joined: Apr 29, 2002
Posts: 200


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.


Be Afraid...Be very Afraid...
Paulo Aquino
Ranch Hand

Joined: Apr 29, 2002
Posts: 200
Already got the answer, I can only use inherited members through inheritance and not through reference calls.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Thanks for sharing what you learned, Paulo!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
 
subject: Protected Method