- package a01;
- public class a01
- {
- public static void main(String[] args)
- {
- Dog x=new Dog("憨憨",2,1.3,"紅棕色");
- Dog y=new Dog("球球",1,1.2,"白色");
- x.showProfile();
- x.makeSound(3);
- y.showProfile();
- y.makeSound(2);
- }
- }
- class Dog
- {
- String name, z;
- int age;
- double w;
- Dog(String name, int age, double w, String z)
- {
- this.name=name;
- this.age=age;
- this.w=w;
- this.z=z;
- }
- void showProfile()
- {
- System.out.println(name+"今年"+age+"歲,體重"+w+"公斤,毛色為"+z);
- }
- void makeSound(int n)
- {
- for(int i=0; i<n;i++)
- System.out.print("汪~");
- }
- }
複製代碼 |