考慮以下例如。這個()在java中應該總是首先執行,如果存在?
public class H{
int a;
public H(){
a=5;
}
public H(String x){
this();
}
{a=0;}
public static void main(String []a){
System.out.print(new H("").a);
}
}
的O/P爲5 這意味着初始化塊第一執行該(前),但根據Why do this() and super() have to be the first statement in a constructor?第一條語句應該是這樣的()。那是怎麼回事?
_first statement_是什麼?引用你的來源。 – 2014-09-02 04:43:18
構造函數中的第一條語句。 – sagar 2014-09-02 04:46:18
初始化器在調用'super'的構造函數之後並在構造函數體的其餘部分之前運行。 – August 2014-09-02 04:47:14