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

TOP

返回列表