Access to java methods of the Object class using an interface reference

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(); // Allowed. Calling methods defined in interface via interface reference.
     cRef.specificMethod(); // Allowed. Calling class specific method via class reference.
     iRef.specificMethod(); // Not allowed. Calling class specific method via interface reference.
     iRef.notify(); // Allowed????

 }

 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?

+4
2

Object

Object, , Object, Java , Object.

JLS & sect; 9.2 - :

:

  • , , - m s, r th t, m s, r throws t Object, , .
+9

, Java , , X, Object, wait(), notify() .

+1

All Articles