Hello friends,
public class Test_Constructor {
int x;
int y;
int z;
//explicit default constructor
/*Test_Constructor() {
x = 10;
y = 20;
z = 30;
System.out.println(x+ "" +y+ "" +z+ " ");
} */
// Non-default constructor
Test_Constructor(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
System.out.println(x+ "" +y+ ""+z+ " ");
}
Test_Constructor(){
this(10,20,0);
System.out.println(x+ "" +y+ ""+z+ " "); }
public static void main(
String[] args) {
Test_Constructor t1 = new Test_Constructor();
Test_Constructor t2 = new Test_Constructor(100,200,300);
}
}
o/p - 10, 20, 0 - this is obvious
10, 20 ,0 - dont know abt this
100,200,300 - this is too
i am getting 3 answers ..can you please explain.
to my mind - 2 outputs are obvious since calling two constructors, but i am confused in the middle one. and can you please explain this() is detail if you can.
- thank you very much
- chintan ramavat