继续转载当年的坑系列,这个系列的题目都是当年从各种坑中收集而来的。

 

 

public class 初始化重载 {
    public static void main(String[] args) {
        new Derived();
    }
}
 
class Base {
    private int i = 2;
     
    public Base() {
        display();
    }
    public void display() {
        System.out.println(i);
    }
}
 
class Derived extends Base {
    private int i = 22;
     
    public Derived() {
        i = 222;
    }
     
    public void display() {
        System.out.println(i);
    }
}

问:会输出什么?
答案:

输出 0

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

required

This site uses Akismet to reduce spam. Learn how your comment data is processed.