从子 class 调用重载函数

Calling overloaded functions from child class

我有 2 个 类 非常相似。假设 birdhawk

class Bird
{
  ...
  public void fly()
  {
    //do a lot of stuff here
  }
}

class Hawk extends Bird
{
  public void fly()
  {
    parent.fly() // how can I call the overloaded parent method?
    //a couple changes specific to hawk here
  }
}

我希望能够同时拥有 Birds 和 Hawks。当在 Hawk 上调用 fly() 时,我仍然想 运行 Bird 的 fly 方法,只是最后有一些变化。我这样做是对的吗?

尝试使用 super 关键字,例如:

class Hawk extends Bird {
    public void fly() {
        super.fly() // use keyword super instead of parent
    }
}

使用超级关键字。当我们想调用 super class method/constructor

时,我们只需使用 Super 关键字
public void fly()
  {
    Super.fly() 
  }