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


  38. }
複製代碼

TOP

返回列表