- public class a02 {
- public static void main(String[] args) {
- Dog a=new Dog("憨憨",2,1.3f,"紅棕色");
- Dog b=new Dog("球球",1,1.2f,"白色");
- a.showProfile();
- a.makeshound(2);
- b.showProfile();
- b.makeshound(3);
- }
- }
- class Dog
- {
- String name,c;
- int s;
- float x;
- Dog(String name,int s,float x, String c)
- {
- this.name=name;
- this.s=s;
- this.x=x;
- this.c=c;
- }
- void showProfile()
- {
- System.out.println(this.name+"今年"+this.s+"歲,體重"+this.x+"公斤,毛色為"+c);
- }
- void makeshound(int n)
- {
- for(int i=1; i<=n; i++)
- {
- System.out.print("汪");
- System.out.println();
- }
- }
- }
複製代碼 |