In Java, how do I call a base class's method from the overriding method in a derived class?

后端 未结 12 921
無奈伤痛
無奈伤痛 2020-11-27 02:50

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

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

class B extends A {
    public          


        
12条回答
  •  庸人自扰
    2020-11-27 02:58

    If u r using these methods for initialization then use constructors of class A and pass super keyword inside the constructor of class B.

    Or if you want to call a method of super class from the subclass method then you have to use super keyword inside the subclass method like : super.myMethod();

提交回复
热议问题