继续转载当年的坑系列,这个系列的题目都是当年从各种坑中收集而来的。
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