/**
* 判断运行结果
*/
public class supertest {
public static void main(String[] args) {
new A(new B());
}
}
class A{
public A(){
System.out.println("A");
}
public A(B b){
this();
System.out.println("AB");
}
}
class B{
public B(){
System.out.println("B");
}
}
答案为:
B
A
AB
/**
* 判断运行结果
*/
public class supertest {
public static void main(String[] args) {
new A(new B());
}
}
class A{
public A(){
System.out.println("A");
}
public A(B b){
this();
System.out.println("AB");
}
}
class B extends A{
public B(){
System.out.println("B");
}
}
答案为:
A
B
A
AB
/**
* 判断运行结果
*/
public class supertest {
public static void main(String[] args) {
Father f = new Father();
Son s = new Son();
System.out.println(f.getInfo());
System.out.println(s.getInfo());
s.test();
System.out.println("-----------------");
s.setInfo("大儿子");
System.out.println(f.getInfo());
System.out.println(s.getInfo());
s.test();
}
}
class Father{
private String info = "father";
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
}
class Son extends Father{
private String info = "儿子";
public void test(){
System.out.println(this.getInfo());
System.out.println(super.getInfo());
}
}
答案为:
father
father
father
father
-----------------
father
大儿子
大儿子
大儿子