POLYMORPHISM

POLYMORPHISM:
Because an instance of a subclass is an instance of its superclass we can handle subclass objects as if they were superclass objects. Furthermore, because a superclass guarantees certain operations in its subclasses we can invoke those operations without caring which the subclass the actual object is an instance of this characteristic is termed ‘polymorphism’ original meaning is having multiple shapes.

 POLYMORPHISM
POLYMORPHISM

1.Example of polymorphism

class Bike{ 
void run(){System.out.println("running");} 
} 
class Splendor extends Bike{ 
void run(){System.out.println("running safely with 60km");} 
public static void main(String args[]){ 
Bike b = new Splendor();//upcasting 
b.run(); 
} 
} 
 
Output:
running safely with 60km.
Translate »