/*多态示例*/
package demo;
class AA {
public void f(){
System.out.println("f in AA");
}
}
class BB extends AA{
public void f(){
System.out.println("f in BB");
}
}
public class Test_Dt {
public static void main(String[] args) {
AA a=new AA();
BB b=new BB();
a.f();
a=b;
a.f();
b=(BB)a;
b.f();
}
}
/*多态失效*/
package demo;
class A{
public static void f(){
System.out.println("f in A");
}
}
class B extends A{
public static void f(){
System.out.println("f in B");
}
}
public class Test {
public static void main(String[] args) {
A a=new A();
B b=new B();
a=b;
//多态在静态方法上失效了
//静态方法是属于类的
a.f();
b.f();
}
}