Polymorphism in Java

Polymorphism In Java

Polymorphism means many forms or more than one form. With the help of polymorphism same method or objects can perform a different operation in different cases.

Example


class Mic{
    void printInfo(){
        System.out.println("Welcome to Default Mic Info");
    }
}

class Boya extends Mic{
void printInfo(){
    System.out.println("Welcome to Boya Mic Info");
}
}

public class PolyWork {
    public static void main(String[] args) {
        Mic m1 = new Mic();
        Boya b1 = new Boya();

        m1.printInfo();
        b1.printInfo();
    }
}
Show Output

Advantage Of Polymorphism

  • It allows us to create consistent code.