blue-sky
blue-sky

Reputation: 53876

What is protected method access level with regard to accessing from another object

I'm passing an object reference to a Util class. I'm attempting to invoke a protected method on the Util class but I getting a compile time error -

The method setPositionChild(Field, int, int) from the type Manager is not visible

To invoke a protected method is it required to be in the implementing class only ? Can I not pass the reference to an external class and invoke the reference from there ?

Upvotes: 4

Views: 11391

Answers (1)

Nishant
Nishant

Reputation: 55866

Protected method can be accessed from subclasses. Make that method public if you want to access from any class. See details here

Also as mentioned by @Sean Patrick Floyd, from classes in the same package!

Upvotes: 7

Related Questions