For the following code lines:
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;
}
}
What should those 2 lines print ?
Base b1 = new Base(10);
Base b2 = new Base(4,7);
I think that if I’ll understand the following line: this(num,num+1); I will understand everything…
thnx
calls following constructor in same object
Why?
If user created an object for
Baseby calling constructor with single param, your code does some default calculations in above constructor and setsnum2anddiffvalues.