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

TOP

返回列表