- class Fu
- {
- int num = 5;
- public Fu()
- {
- show();
- System.out.println("第二次打印:"+num);
- }
- void show()
- {
- System.out.println(num);
- }
- }
- class Zi extends Fu
- {
- int num = 3;
- public Zi()
- {
- //super(); //隐式语句空参的super(),子类对象初始化时,父类构函也会运行
- }
- void show()
- {
- System.out.println("第一次打印:"+num);
- }
- }
- class Demo
- {
- public static void main(String[] args)
- {
- Zi f = new Zi();
- }
- }
复制代码
也就是说:建立Zi对象后 Zi的构造函数初始化,接着super()指向父类的Fu空参构造函数
因为空参的构造方法里面是show()方法先所以打印Zi的show,接着打印Fu的空参println语句 |