Speed up development with full-stack environments for every branch.

Learn More

Java Dynamic Polymorphism Example

407 Runs 1967 Views 710 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

/*
* Java Dynamic Polymorphism Example
*/

class Vehicle{
    public void move(){
    System.out.println("Vehicles can move!!");
    }
}

class MotorBike extends Vehicle{
    public void move(){
    System.out.println("MotorBike can move and accelerate too!!");
    }
}

class HelloWorld{
    public static void main(String[] args){
    Vehicle vh=new MotorBike();
    vh.move();    // prints MotorBike can move and accelerate too!!
    vh=new Vehicle();
    vh.move();    // prints Vehicles can move!!
    }
}
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).