What is Polymorphism?

Polymorphism allows objects to be represented in multiple forms. Even though classes are derived or inherited from the same parent class, each derived class will have its own behavior. Polymorphism is a concept linked to inheritance and assures that derived classes have the same functions even though each derived class performs different operations.
Polymorphism is possibility to change behavior with objects depending of object’s data type. In C# polymorphism realizes through the using of keyword virtual and override. Let look on the example of code:

public virtual void Out()
Console.WriteLine(“Aperture virtual method called”);
//This method is defined in Aperture class.
public override void Out()
Console.WriteLine(“Door virtual method called”);

Leave a Reply

Your email address will not be published. Required fields are marked *