interface Intf {
}
class A implements Intf {
}
class Test {
public static void main(String[] args) {
Intf obj = new A();
obj.toString();
}
}
A friend showed me this code, I could not explain it to him ...
We know that methods defined in a "specified" object can only be executed on an instance. As we can see, no method is defined Intf, but obj (which refers to Intf) is able to call the method toString()of the Object.class object
I consoled him by saying that this is all an object in Java (although we do not get the autocomplete option in the eclipse IDE against Intf)
source
share