java 继承与多态

Example5_11.java

class  动物 {
   void cry() {
   }  
}
classextends 动物 {
   void cry() {
      System.out.println("汪汪....."); 
   }  
}
classextends 动物  {
   void cry() {
      System.out.println("喵喵....."); 
   }  
}
public class Example5_11 { 
   public static void main(String args[]) {
      动物 animal;
      animal = new 狗();
      animal.cry(); 
      animal=new 猫();
      animal.cry();
  }
}

 

相关文章:

  • 2021-08-27
  • 2021-10-21
  • 2022-01-08
  • 2022-12-23
  • 2021-07-05
猜你喜欢
  • 2021-07-20
  • 2022-12-23
  • 2021-05-08
  • 2021-05-24
  • 2022-02-10
相关资源
相似解决方案