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

TOP

返回列表