在Java中,如何从派生类中的重写方法调用基类的方法?

在Java中,如何从派生类中的重写方法调用基类的方法?

问题描述:

我有两个Java类:B,它扩展了另一个类A,如下所示:

I have two Java classes: B, which extends another class A, as follows :

class A {
    public void myMethod() { /* ... */ }
}

class B extends A {
    public void myMethod() { /* Another code */ }
}

我想拨打 A.myMethod( )来自 B.myMethod()。我来自 C ++ world ,我不知道如何用Java做这个基本的事情。

I would like to call the A.myMethod() from B.myMethod(). I am coming from the C++ world, and I don't know how to do this basic thing in Java.

你要找的关键字是。例如,请参见本指南

The keyword you're looking for is super. See this guide, for instance.