public class ThisDemoTwo
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
//构造函数间的调用要使用关键字this(无参,参数1,参数2...)
class Person
{
private int age;
private String name;
Person()
{
this("666");//不允许这样使用,因为只有一个参数的构造函数也调用了无参的构造函数,会与此构造函数形成死循环
}
Person(int age)
{
this();//调用了无参的构造函数
this.age=age;
}
Person(int age,String name)
{
//this.age=age;
this(age);//调用了只有一个参数的构造函数
this.name=name;
}
}