Consider the following example.
public interface SimpleInterface {
public void simpleMethod();
}
public class SimpleClass implements SimpleInterface{
public static void main(String[] args) {
SimpleInterface iRef = new SimpleClass();
SimpleClass cRef = new SimpleClass();
iRef.simpleMethod();
cRef.specificMethod();
iRef.specificMethod();
iRef.notify();
}
public void specificMethod(){}
@Override
public void simpleMethod() {}
}
I thought that in Java using an interface reference, we can only access the methods that are defined in that interface. But, it seems, he is allowed access to the method of the Object class through any link to the interface. My particular "SimpleClass" class inherits all the methods that the Object class has, and definitely the Object class does not implement any interface (we can assume that Object implements some interface with methods such as notification, wait, etc.). My question is why is it allowed to access the methods of the Object class through a link to the interface, taking into account that other methods in my particular class are not allowed?