Skip to content

Polymorphism

Question

Describe polymorphism.

Short interview answer

Polymorphism lets code use a base-class or interface contract while the runtime dispatches behavior to the concrete implementation. For example, a collection of IShape values can call Draw() on circles and rectangles without caller-specific branching.

Detailed answer

Subtype polymorphism is the usual C# interview meaning: a variable declared as a base type or interface can refer to different implementations. Virtual methods and interface members enable the runtime to choose the appropriate implementation. This helps separate callers from concrete types, but it should model a real substitutable contract rather than be added for its own sake.

Sources