QuickDevGuide

Home › OOPs

Polymorphism — OOPs

Polymorphism means "many forms" — it allows a single method to behave differently depending on the object that calls it. A single method call can produce different results depending on the object's actual type. Two Types of Polymorphism a) Compile-Time Polymorphism (Method Overloading) — Same method name with different parameters within the same class. The compiler decides which method to call based on the argument types/count. For example, a Calculator class can have add(int a, int b) and add(int a, int b, int c). b) Run-Time Polymorphism (Method Overriding) — A subclass provides a different implementation of a method already defined in its parent class. The JVM decides which method to call at runtime based on the actual object type. For example, Dog overrides Animal's sound() method…

Key Takeaways