- public class A {
- public static void main(String[] args) {
- Dog d1=new Dog("dog 1", 2, 1.3, "brown");
- Dog d2=new Dog("dog 2", 1, 1.2, "white");
- d1.showProfile();
- d1.makeSound(2);
- d2.showProfile();
- d2.makeSound(3);
- }
- }
- class Dog {
- String name, color;
- double w;
- int age;
-
- Dog(String n, int a, double w, String c)
- {
- name=n;
- age=a;
- this.w=w;
- color=c;
- }
-
- void showProfile()
- {
- System.out.println(name+"age"+age+"weight"+w+"color of fur"+color+".");
- }
-
- void makeSound(int n)
- {
- for(int i=1; i<=n; i++)
- System.out.print("woof");
- System.out.println();
- }
- }
複製代碼 |