首页 > 代码库 > 设计继承树1

设计继承树1

 1 public class Sheji extends Animals{ //继承Animal 2     void makeNoise(){ //重写makeNoice方法 3         System.out.println(name+"汪汪汪!"); 4     } 5     void eat(){ 6         System.out.println(name+"在高兴地吃"+food); 7         System.out.println(name+"饥饿程度是:"+hunger+"级"); 8     } 9   public static void main(String[] args){10       Sheji Dog = new Sheji();11       Dog.name = "旺财";12       Dog.food = "屎";13       Dog.hunger = 1;14       15       Dog.makeNoise();16       Dog.eat();17   }18 }19 class Animals{20     String name;21     String food;22     int hunger;23     24     void makeNoise(){25         26     }27     void eat(){28         29     }30     void sleep(){31         32     }33     void roam(){34         35     }36 }

技术分享

设计继承树1