構造函數之間調用

構造函數之間調用只能用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;
	}


 

 

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