写出以下代码的输出结果?

package com.djh.face;

public class Dispatch {
    public static void main(String[] args) {
        Base b = new Sub();
        System.out.println(b.x);
    }
}

class Base{
    int x = 10;
    public Base(){
        this.printMessage();
        x=20;
    }
    
    public void printMessage(){
        System.out.println("Base.x="+x);
    }
}

class Sub extends Base{
    int x = 30;
    public Sub(){
        this.printMessage();
        x=40;
    }
    public void printMessage(){
        System.out.println("Sub.x="+x);
    }
}

 

posted on 2016-05-10 22:38  dangjunhui  阅读(581)  评论(1编辑  收藏  举报

导航