- package a01;
- public class a01 {
- public static void main(String[] args)
- {
- // TODO 自動產生的方法 Stub
- Dog d1= new Dog("憨憨",2,1.3f,"紅棕色");
- Dog d2= new Dog("球球",1,1.2f,"白色");
- d1.showProfile();
- d1.makeSound(2);
- System.out.println();
- d2.showProfile();
- d2.makeSound(3);
- }
- }
- class Dog
- {
- String name,c;
- int a;
- float w;
- Dog(String name, int a,float w,String c)
- {
- this.name=name;
- this.a=a;
- this.w=w;
- this.c=c;
- }
- void showProfile()
- {
- System.out.println(name+"今年"+a+"歲,體重"+w+"公斤,毛色為"+c);
- }
- void makeSound(int n)
- {
- for (int i = 0; i < n; i++) {
- System.out.print("旺~");
- }
- }
- }
複製代碼 |