首页 > 编程语言 > 详细

java实例变量及方法调用顺序

时间:2016-08-12 13:20:26      阅读:182      评论:0      收藏:0      [点我收藏+]
public class Base {
    private String name="base";

    public Base(){
        sayHello();
    }
    void sayHello() {
        System.out.println("Base hello " + name);
    }
}

class Derived extends Base {
    private String name="Derived";

    public Derived(){
        sayHello();
    }

    void sayHello() {
        System.out.println("Derived hello " + name);
    }
}

public class Main {
    public static void main(String[] args) {
        Base b = new Derived();
    }
}

 

Derived hello null
Derived hello Derived

 

java实例变量及方法调用顺序

原文:http://www.cnblogs.com/yasepix/p/5764365.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!