日期:2014-05-20 浏览次数:20771 次
public class A {
public int num;
public A() {
System.out.println("A");
System.out.println("a-class" + this.getClass());
System.out.println("a-class" + super.getClass());
}
public A(int num) {
this.num = num;
System.out.println("a-class" + this.getClass());
System.out.println("a-class" + super.getClass());
System.out.println("a-num" + num);
}
public int sub(int n) {
return this.num + n;
}
@Override
public String toString() {
return "A [getClass()=" + this.getClass();
}
}
public class B extends A {
public int num;
public B() {
System.out.println("B");
System.out.println("b-class" + this.getClass());
System.out.println("b-class" + super.getClass());
}
public B(int num) {
super(num + 1);
this.num = num;
System.out.println("b-class" + this.getClass());
System.out.println("b-class" + super.getClass());
System.out.println("b-num" + num);
}
public int sub(int n) {
return super.num + n;
}
@Override
public String toString() {
return "B [getClass()=" + this.getClass();
}
}
public class C extends B {
public C() {
System.out.println("C");
System.out.println("c-class" + this.getClass());
System.out.println("c-class" + super.getClass());
}
public C(int num) {
super(num + 1);
System.out.println("c-num" + num);
System.out.println("c-class" + this.getClass());
System.out.println("c-class" + super.getClass());
}
public int sub(int n) {
return super.num + n;
}
@Override
public String toString() {
return "C [getClass()=" + this.getClass();
}
}
public class Test1 {
public static void main(String[] args) {
C c1 = new C();
}
}
A