返回列表 發帖
  1. public class ch64
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         Dog d1=new Dog("憨憨",2,3.8);
  6.         Dog d2=new Dog("球球",1,2.5);
  7.         Cat c1=new Cat("咪咪",5,3.2);
  8.         d1.showProfile();
  9.         d2.showProfile();
  10.         c1.showProfile();
  11.     }
  12. }
  13. class Animal
  14. {
  15.     String name;
  16.     int age;
  17.     double w;
  18.     Animal(String name, int age, double w)
  19.     {
  20.         this.name=name;
  21.         this.age=age;
  22.         this.w=w;
  23.         sum++;
  24.     }
  25.     void showProfile()
  26.     {
  27.         System.out.println(name+"今年"+age+"歲,體重"+w+"公斤.");
  28.     }
  29. }
  30. class Dog
  31. {
  32.      Dog(String name, int age, double w)
  33.     {
  34.         super(name ,age , w);
  35.     }
  36. }
  37. class Cat
  38. {
  39.      Cat(String name, int age, double w)
  40.     {
  41.         super(name ,age , w);
  42.     }
  43. }
複製代碼

TOP

返回列表