[@talishboy][¥20]多层内部类继承,最内层的类如何实例化。(例如三层)
/**
* @author Gjing
**/
public class A {
int getNum(){
return 10;
}
public void fun(){
System.out.println('你今天真好看!');
}
}
class B extends A{
public String getName(){
//B类继承A类
return '张三';
}
@Override
public void fun(){//方法覆写
System.out.println(this.getNum());
}
}
/**
* C类继承B类,相当于间接继承A类
*/
class C extends B{
@Override
public void fun(){
System.out.println(this.getName());
}
}
class Test{
public static void main(String[] args){
print(new A());
print(new B());
print(new C());
}
private static void print(A a){
a.fun();
}
}
赞0
踩0