- class Fu
- {
- Fu()
- {
- System.out.println("fu run");
- }
- }
- class Zi extends Fu
- {
- Zi()
- {
- //super();子类构造函数第一行中都有一个隐式的父类构造函数super(),这里的super()等同于Fu();
- //所以在执行子类构造函数时都会执行父类的这个隐式构造函数
- System.out.println("zi run");
- }
- Zi(int x)
- {
- //super();//同上面
- System.out.println("zi..."+x);
- }
- }
- class ExtendsStudy
- {
- public static void main(String[] args)
- {
- Zi z = new Zi();//执行过程Fu()-->Zi()
- Zi z1 = new Zi(3);//执行过程Fu()-->Zi(int x)
- }
- }
复制代码
打印结果:
fu run
zi run
fu run
zi...3 |