- public class ch64
- {
- public static void main(String args[])
- {
- Dog d1=new Dog("憨憨",2,3.8);
- Dog d2=new Dog("球球",1,2.1);
- Cat c1=new Cat("咪咪",5,3.2);
- d1.showProfile();
- d2.showProfile();
- c1.showProfile();
- }
- }
- class Animal
- {
- String name;
- int age;
- double w;
- Animal(String name, int age, double w)
- {
- this.name=name;
- this.age=age;
- this.w=w;
- }
- }
- class Dog extends Animal
- {
- Dog(String name, int age, double w)
- {
- super(name ,age ,w);
- }
- }
- class Cat extends Animal
- {
- Cat(String name, int age, double w)
- {
- super(name ,age ,w);
- {
- }
複製代碼 |