📜  借助代码显示 this() 和 super() 之间的区别 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:06.584000             🧑  作者: Mango

代码示例1
class Animal {
  void eat() {
    System.out.println("animal : eat");
  }
}

class Dog extends Animal {
  void eat() {
    System.out.println("dog : eat");
  }
  void anotherEat() {
    super.eat();
  }
}

public class Test {
  public static void main(String[] args) {
    Animal a = new Animal();
    a.eat();
    Dog d = new Dog();
    d.eat();
    d.anotherEat();
  }
}