Back to course

Polymorphism and Method Overriding

C# Zero to Hero: Comprehensive Programming Masterclass

Polymorphism

Polymorphism means "many shapes". It allows objects of different types to be treated as objects of a common base type.

Method Overriding

Use virtual in the parent and override in the child. csharp class Animal { public virtual void MakeSound() => Console.WriteLine("..."); }

class Dog : Animal { public override void MakeSound() => Console.WriteLine("Bark!"); }