package FileDemo; import java.time.Month; import java.util.Iterator; import java.util.LinkedList; /** * Created by ZL on 2016/8/14. */ public class Test03 { int var; Test03(double var) { this.var = (int) var; } Test03(int var) { this("hello"); } Test03(String s) { this(); System.out.println(s); } Test03() { System.out.println("good-bye"); } public static void main(String [] args) { Test03 t = new Test03(5); } }
输出结果:
good-bye hello
构造方法第一行默认super() 调用无参的构造方法,也就是父类的无参构造方法,由于被子类重写了,于是会调用子类的构造方法。
时间: 2024-10-10 04:17:15