class Demo8Extends
{
public static void main(String[] args)
{
Dog dog = new Dog();
}
}
class Animal
{
String name = "我是一只动物";
public Animal(){}
public Animal(String name){
this.name = name;
System.out.println("父类构造方法");
}
public void eat(){
System.out.println("吃了");
}
}
class Dog extends Animal
{
public Dog(){
//super("洪志");
System.out.println("子类构造方法");
}
public void eat(){
System.out.println("喵吃了");
}
public void eat(String food){
System.out.println("喵吃了"+food);
}
public void show(){
System.out.println("show!");
}
}
|
|