I have below code written with Eclipse ide:
public interface X
{
final public static int SOME_CONST = 0;
}
public class Handle implements X
{
protected void methodHandle () { }
//...
}
public class User implements X
{
Handle handle = new Handle();
private void methodUser ()
{
Y y = new Y() // anonymous inner class
{
public void methodY ()
{
handle.methodHandle (); // <--- why this is NOT giving error ?
}
}
}
}
Even though Handle.methodHandle () is protected, it’s still callable from the inner method of an anonymous inner class method ? Why is it happening, am I missing something ? The only relation between Handle and User is that they are implementing same X.
If both classes are in the same package, the protected method can be called.
See this for more details.