本帖最后由 涧澜 于 2011-12-10 16:20 编辑
为什么this();只能用在构造函数第一行?那this所在构造函数要对已构造函数多次引用呢?形如:
class Person
{
private int age;
private String name;
private String occupation;
Person(String name)
{
this.name=name;
System.out.println(name);
}
Person(String name,int age)
{
this.name=name;
this.age=age;
System.out.println(name+"..."+gae);
}
Person(int age,String name,String occupation)
{
this(name);//把两个this();的位置调换两个都报错,问为什么会这样?
this(age);//这儿就报错了,为什么把这句注释掉,把this(name);改为this(name,age);就ok了?
this.occupation=occupation;
System.out.println(name+"..." +age+"..."+occupation);
} |