不不不,没这么简单
class ThisAndSuper {
public static void main(String[] args) {
A a = new B();
}
}
class A {
int i = 0;
public A(){
this.play();
System.out.println(i);
}
public void play(){
System.out.println("我是A");
}
}
class B extends A {
int i = 10;
public B(){
this.play();
System.out.println(i);
}
public void play(){
System.out.println("我是B");
}
}
class ThisAndSuper2 {
public static void main(String[] args) {
B b = new C();
}
}
class A {
int i = 0;
public A(){
}
public void play(){
System.out.println("我是A");
}
}
class B extends A {
int i = 10;
public B(){
super.play();
System.out.println(i);
}
public void play(){
System.out.println("我是B");
}
}
class C extends B {
int i = 20;
public C(){
super.play();
System.out.println(i);
}
public void play(){
System.out.println("我是C");
}
}
你可以试试 |