- package owo;
- public class owo {
- public static void main(String[] args)
- {
- Dog red=new Dog("憨憨",2,1.3f,"紅棕色");
- Dog white=new Dog("球球",1,1.2f,"白色");
- red.show();
- red.shound(2);
- white.show();
- white.shound(3);
-
-
- }
- }
- class Dog
- {
- String name,color;
- int y;
- float kg;
-
- Dog(String x,int u,float h,String p)
- {
- name=x;
- y=u;
- kg=h;
- color=p;
- }
- void show()
- {
- System.out.println(name+"今年"+y+"歲、"+kg+"公斤、毛色為"+color);
- }
- void shound(int n)
- {
- for(int i=0;i<n;i++)
- {
- System.out.print("汪~");
- }
- System.out.println();
- }
- }
複製代碼 |