Image for Dynamic polymorphism

Dynamic polymorphism

Dynamic polymorphism is a programming concept where a program decides which method to execute at runtime, rather than compile time. This allows objects of different classes to be treated as instances of a common superclass, but with each object responding in its own way when a method is called. For example, a “shape” class might have a “draw” method; circles and squares inherit from "shape" and each implements “draw” differently. When invoking “draw” on a shape, the program dynamically determines whether to draw a circle or square based on the actual object, enabling flexible and extendable code.