package java02;
//父类的某个方法被其子类重写时,可以各自产生自己的功能行为;
//当把子类创建的对象引用赋给一个父类对象时(向上转型),
//这个向上转型对象在调用这个实例方法时,就可能具有多种形态。
class F {
int fun(int t) {
return t;
}
}
class A extends F {
int fun(int t) {
return t * t;
}
}
class B extends F {
int fun(int t) {
return t * t * t;
}
}
class C extends F {
int fun(int t) {
return t * t * t * t;
}
}
public class 类的继承多态2 {
public static void main(String[] args) {
int a, b, c, d;
F f = new F();
a = f.fun(2);
f = new A();
b = f.fun(2);
f = new B();
c = f.fun(2);
f = new C();
d = f.fun(2);
System.out.println(a);
System.out.println(b);
System.out.println©;
System.out.println(d);
System.out.println(a + b - c + d);
}
}