views:

3611

answers:

7

Hello everybody, 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 */ }
}

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

+1  A: 

call super.myMethod();

Elie
+6  A: 

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

unwind
+9  A: 

Just call it using super.

    public void myMethod()
    {
        // B stuff
        super.myMethod();
        // B stuff
    }
Robin
+1  A: 

Use the super keyword.

Steve K
+2  A: 

super.MyMethod()

geeeeeeeeeek
A: 

Woooow ! What a fast answer ! Thank you very much.

Le Barde
A: 

I have further question, i.e. how to do it outside the overriden method?

ohu