在Java中,如何从派生类中的重写方法调用基类的方法? [英] In Java, how do I call a base class's method from the overriding method in a derived class?

查看:506
本文介绍了在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.

这篇关于在Java中,如何从派生类中的重写方法调用基类的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆