JAVA多态实现子类的不断增加

public class C {
public void f()
{
System.out.printf("CCC\n");
}

}

public class D extends C{
public  void f() 
{

    System.out.printf("DDD\n");

}

}

public class Exercise2 {
public static void g(C cc)
{
cc.f();
}

public static void main(String[] args) {
    D dd1=new D();
    C cc1=new C();

    g(cc1);
    g(dd1);

} 

}

转载于:https://blog.51cto.com/13930723/2355866

你可能感兴趣的:(JAVA多态实现子类的不断增加)