假定 Grand,Father和Son在同一个包, 问父类和子类中通过this和super都可以调用哪些属性和方法
class Grand {
String name = "AA";
private int age = 100;
public void g1(){}
}
class Father extends Grand{
String id = "001";
private double score;
public void f1() {
//super可以访问哪些成员(属性和方法)?
//this可以访问哪些成员?
}
}
class Son extends Father {
String name = "BB";
public void g1() {}
private void show(){
//super可以访问哪些成员(属性和方法)?
//this可以访问哪些成员?
}
}
答案
father中
super:super.name super.g1()
this: this.id , this.score? ?this.f1()? this.name? ?this.g1()
Son中
super:super.id? super.f1()??super.name? super.g1()
this:?this.name? ?this.g1()? this.show()??this.id? ???this.f1()
|