對於下面的代碼行:簡單的Java構造
public class Base{
private int num1 = 0;
private int num2 = 0;
private static int dif = 0;
public Base(int num){
this(num,num+1);
System.out.println("Base constructor1");
}
public Base(int num1, int num2){
System.out.println("Base constructor2");
this.num1 = num1;
this.num2 = num2;
dif = num2 - num1;
}
public int sum(){
return num1 + num2;
}
public static int getDif(){
return dif;
}
}
應該怎樣那些2線打印?
Base b1 = new Base(10);
Base b2 = new Base(4,7);
我想,如果我要了解以下行:this(num,num+1);
我就明白了一切...
日Thnx
請嘗試並縮進您的代碼。使它更容易閱讀 – 2012-08-14 14:39:28
this(num,num + 1);調用public Base(int num1,int num2) – NimChimpsky 2012-08-14 14:40:11
如果你在調試器中遍歷你的代碼,你可以看到每行代碼。 – 2012-08-14 14:54:05