interface A {
void hi();
}
class AImpl implements A {
public void hi() {
System.out.println("hi");
}
public void to() {
System.out.println("Test");
}
}
public class InterfaceTest {
public static void main(String[] args) {
A a = new AImpl();
a.hi();
System.out.println(a.hashCode());
//a.to();
}
}
here interface A has no inheritance relationship with Object class but all the mehods of Object class can be access through the interface.
why?
From the Java Language Specification section 9.2:
The third bullet is the important one – basically interfaces which don’t extend any other interfaces automatically inherit
hashCodeetc.