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

TOP

返回列表