阅读背景:

面向对象(this关键字在构造函数间调用)

来源:互联网 

/*
结构函数间调用,只能用this(参数)
this调用只能放在结构函数中的第一行。由于初始化要先履行。
*/
class Person{
	private String name;
	Private int age;
	
	Person(){
		
	}
	
	Person(String name){
		this();
		this.name = name;
	}
	Person(String name,int age){
		this(name);//这行表现p(name);
		this.age = age;
	}
}

class Test{
	public static void main(String[] args){
		Person p = new Person("lisi",20);
		Person p1 = new Person("hhh",23);
	}
}/*
结构函数间调用,只能用this(参数)
this调用只能放在结构函数中的第一行。由于初始化要先




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: