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

TOP

返回列表