返回列表 發帖
  1. package a01;

  2. public class a01 {

  3.         public static void main(String[] args)
  4.         {
  5.                 // TODO 自動產生的方法 Stub
  6.                 Dog d1= new Dog("憨憨",2,1.3f,"紅棕色");
  7.         Dog d2= new Dog("球球",1,1.2f,"白色");      
  8.         d1.showProfile();
  9.         d1.makeSound(2);
  10.         System.out.println();
  11.         d2.showProfile();
  12.         d2.makeSound(3);
  13.             }

  14. }
  15. class Dog
  16. {
  17. String name,c;
  18. int a;
  19. float w;
  20. Dog(String name, int a,float w,String c)
  21. {
  22.     this.name=name;
  23.     this.a=a;
  24.     this.w=w;
  25.     this.c=c;
  26. }

  27. void showProfile()
  28. {
  29.     System.out.println(name+"今年"+a+"歲,體重"+w+"公斤,毛色為"+c);
  30.         }
  31. void makeSound(int n)
  32. {
  33.         for (int i = 0; i < n; i++) {
  34.                 System.out.print("旺~");               
  35.         }
  36. }
  37. }
複製代碼

TOP

返回列表