返回列表 發帖
  1. public class ch59
  2. {
  3.     public static void main(String args[])
  4.     {
  5.                 Dog d[]={new Dog("stupid","透明",100,1000),new Dog("bitch","彩色",-5,1234.6)};
  6.                 d[0].showProfile();
  7.                 d[0].makeSound(100);
  8.                 d[1].showProfile();
  9.                 d[1].makeSound(100);
  10.     }
  11. }
  12. class Dog
  13. {
  14.     String name,color;
  15.     int age;
  16.         double weight;
  17.         Dog(String n,String c,int a,double w)
  18.         {
  19.                 name=n;
  20.                 color=c;
  21.                 age=a;
  22.                 weight=w;
  23.         }
  24.         void showProfile()
  25.         {
  26.                 System.out.println(name+"今年"+age+"歲, 體重"+weight+"公斤,毛色為"+color);
  27.         }
  28.         void makeSound(int m)
  29.         {
  30.                 for(int i=1;i<=m;i++)
  31.                         System.out.print("汪~");
  32.                 System.out.println();
  33.         }
  34. }
複製代碼

TOP

返回列表