//父类public class Person {public void run(){System.out.println("跑、跑、跑");}}//子类public class Student extends Person{//继承public void run(){//重写System.out.println("背着书包跑");}}public class Test {public static void main(String[] args) {Person p = new Student();//父类引用指向子类对象p.run();}}
多态,又称动态加载机制,形成多态的三个要素:继承、父类引用指向子类对象、重写 。