Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is uesed to refer to a child class object
1. 多态的例子
public interface Vegetarian {}
public class Animal {}
public class Deer extends Animal implements Vegetarian {}
// a Deer IS-A Animal
// a Deer IS-A Vegetarian
// a Deer IS-A Deer
// a Deer IS-A Object
2. 虚函数(virtual method)
Java并没有virtual关键字,其多态的实现依赖于运行时刻对象实际类型。
编译阶段,编译器会根据引用声明的类型进行类型检查。
运行阶段,一个引用很可能引用的是其子类的对象,因此运行时刻,JVM会调用引用所指对象实际类型的相应方法。