Call the method of base Class which was over ridden

Posted by Abhijith Venkata on Stack Overflow See other posts from Stack Overflow or by Abhijith Venkata
Published on 2012-09-15T15:06:25Z Indexed on 2012/09/15 15:37 UTC
Read the original article Hit count: 268

Filed under:
|

I have illustrated my question in this example

class Car {
    public void start(){
        System.out.println("Car Started!!!");
    }
}

class Mercedes extends Car {
    public void start(){
        System.out.println("Mercedes Started!!!");
    }
}

Now, in my main program, I write

Mercedes m = new Mercedes();
m.start();

It prints: Mercedes Started!!!

How do I call the start() method of Car class using the same object so that the output can be

Car Started!!!.

Edit:

Actually It was asked in an interview I attended. I gave the super keyword answer. But the interviewer denied it. He said he'd give me a hint and said Virtual Function. I have no idea how to use that hint.

© Stack Overflow or respective owner

Related posts about java

Related posts about inheritance