java运行时动态绑定

class Person{
    public void run(){
        System.out.println("PERSON");
    }
    public void work(){
        run();
    }
}

public class Main3 extends Person {
    public void run(){
        System.out.println("MAIN");
    }
    public static void main(String[] args) {
        Main3 m= new Main3();
        m.work();
    }
}
//输出
//MAIN

你可能感兴趣的:(java运行时动态绑定)