package com.imooc;
public class Animal {
public int age = 10;
public String name;
public void eat(){
System.out.println("年龄:"+age+"动物具有吃东西的能力!");
}
public Animal(){
System.out.println("Animal类执行了");
age = 20;
}
}
package com.imooc;
public class Dog extends Animal {
public void eat(){
System.out.println("年龄:"+age+"狗具有吃东西的能力!");
}
public Dog(){
System.out.println("Dog类执行了");
}
}
package com.imooc;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Animal animal = new Animal();
System.out.println("animal age:"+animal.age);
Dog dog = new Dog();
dog.age = 10;
dog.name = "xiaohua";
dog.eat();
}
惟愿_无事常相见
qq_残局_03390168
相关分类