File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Protected Method" Watch "Protected Method" New topic

Protected Method

Paulo Aquino
Ranch Hand

Joined: Apr 29, 2002
Posts: 202

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: 202
Already got the answer, I can only use inherited members through inheritance and not through reference calls.
Dirk Schreckmann

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

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Protected Method
jQuery in Action, 3rd edition