A)
class vehicle
{
void stop()
{
System.out.println("Vehicle stopped");
}
void move()
{
System.out.println("Vehicle moved");
} //overridden method
}//super class
class car extends vehicle
{
void move()
{ // super.move();
// with this super.move() method call.
// we call the parent class method which is overridden
System.out.println("As a car I move in any own way also");
}//overriddingmethod
}//sub class
public class Methodoverriding {
public static void main(String[] args) {
car c = new car();
c.stop();
c.move();
}
}
Output:
Vehicle stopped
As a car I move in any own way also
Comments
Post a Comment