public class Anmial { public Anmial(){ eat(); } public void eat(){ System.out.println("动物有吃的功能"); }}
public class Dog extends Anmial{ public String name; public Dog(String name) { this.name = name; } public void eat(){ // System.out.println(name.length()); System.out.println("狗吃肉"); } public static void main(String[] args) { Dog dog = new Dog("馒头"); } }
继承(狗继承动物)
最新推荐文章于 2022-12-11 15:46:19 发布