返回列表 發帖
  1. public class Chseer61
  2. {
  3.   public static void main(String args[])
  4.   {
  5.     Dogg d1=new Dogg("憨憨(對面的XX)",2,1.3,"紅棕色");
  6.     Dogg d2=new Dogg("球球(不是我)",1,1.2,"白色");
  7.         d1.showProfile();
  8.         d1.makeSound(2);
  9.             d2.showProfile();
  10.             d2.makeSound(3);
  11.   }
  12. }
  13. class Dogg
  14. {
  15.   String name, color;
  16.   int age;
  17.   float weight;
  18.   Dogg(String name, int age, float weight, String color)
  19.   {
  20.     this.name=name;
  21.         this.age=age;
  22.             this.weight=weight;
  23.                     this.color=color;
  24.   }
  25.   void showProfile()
  26.   {
  27.     System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤,毛色為"+color);
  28.   }
  29.   void makeSound(int n)
  30.   {
  31.     for(int i=0; i<n; i++)
  32.       System.out.print("消音~");
  33.     System.out.println();
  34.   }
  35. }
複製代碼

TOP

返回列表