class Child1 implements Parent
{
public String method()
{
return "Child1";
}
}
class Child2 implements Parent
{
public String method()
{
return "Child2";
}
}
public class Test
{
public static void main(String[] args)
{
Parent parent = new Child1();
System.out.println(parent.method());
parent = new Child2();
System.out.println(parent.method());
}
}
The Java Virtual Machine does not require any particular internal structure for objects. In Sun's current implementation of the Java Virtual Machine, a reference to a class instance is a pointer to a handle that is itself a pair of pointers: one to a table containing the methods of the object and a pointer to the Class object that represents the type of the object, and the other to the memory allocated from the Java heap for the object data. (jvm规范中关于对象内存布局的说明)