Java编译时根据调用该方法的类或对象所属的类决定

class Base{

    int x = 1;

    static int y = 2;

}

class Subclass extends Base{

    int x = 4;

    int y = 5;

}

public class Test02{

    public static void main(String[] args){

        Subclass s = new Subclass();

        System.out.println(s.x+" "+s.y);

        Base s1 = new Subclass();

        System.out.println(s1.x+" "+s1.y);

    }

}

 

/*

* 实验结果:4 5

            1 2

 

* 实验结论:编译时根据调用该方法的类或对象所属的类决定

*/

posted @ 2015-09-22 12:41  iucforever  阅读(325)  评论(0编辑  收藏  举报