class X{
int x;
X(int x){
System.out.println("X Constructor");
this.x = x;
}
}
class Y extends X{
int y;
Y(int x, int y){
super(x); //superキーワード(コンストラクタ)
System.out.println("Y Constructor");
this.y = y;
}
}
class Z extends Y{
int z;
Z(int x, int y, int z){
super(x, y); //superキーワード(コンストラクタ)
System.out.println("Z Constructor");
this.z = z;
}
}
//
public class TestCons {
public static void main(String[] args) {
System.out.println("Start");
//
System.out.println("------------------------");
//
Z Obj = new Z(1, 2, 3);
System.out.println("X -> " + Obj.x);
System.out.println("Y -> " + Obj.y);
System.out.println("Z -> " + Obj.z);
System.out.println("");
//
System.out.println("------------------------");
System.out.println("End");
}
}
|