今天用學校里的黑馬程序員通Java語法
想到了:在有參構造函數中調用無參構造函數
語法是這樣的:
class Person{ private int age; public Person() { System.out.println("wu can gou zao"); } public Person(int a) { age = a; System.out.println("you can gou zao"); System.out.println("age shi"+ a);
this();
} }
報錯:Constructor call must be the first statement in a constructor
即 構造函數調用必須是構造函數中的第一個語句
在構造方法中,調用另一個構造函數時,必須在第一條語句中調用。
並且不能兩個構造函數相互調用,這樣不就成遞歸了么。