构造函数之间调用

构造函数之间调用只能用this关键字,通过参数区分所调用的构造函数

可以这样理解: this.age中的this为this关键字,而this(age)中的this为this语句,它起到调用函数的作用.the example:

	private String name;
	private int age;
	public TestConstructor(String name){
		this.name=name;
	}
	public TestConstructor(int age,String name){
		this(name);
		this.age=age;
	}


 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章