- public class ch59
- {
- public static void main(String args[])
- {
- Dog d[]={new Dog("stupid","透明",100,1000),new Dog("bitch","彩色",-5,1234.6)};
- d[0].showProfile();
- d[0].makeSound(100);
- d[1].showProfile();
- d[1].makeSound(100);
- }
- }
- class Dog
- {
- String name,color;
- int age;
- double weight;
- Dog(String n,String c,int a,double w)
- {
- name=n;
- color=c;
- age=a;
- weight=w;
- }
- void showProfile()
- {
- System.out.println(name+"今年"+age+"歲, 體重"+weight+"公斤,毛色為"+color);
- }
- void makeSound(int m)
- {
- for(int i=1;i<=m;i++)
- System.out.print("汪~");
- System.out.println();
- }
- }
複製代碼 |