Mid From PDF OOP C# OOP

Give an example of polymorphism in C#.?

abstract class Shape { public abstract void Draw(); }

class Circle : Shape { public override void Draw() =>

Console.WriteLine("Drawing Circle"); }

class Rectangle : Shape { public override void Draw() =>

Console.WriteLine("Drawing Rectangle"); }

Shape s1 = new Circle();
Shape s2 = new Rectangle();

s1.Draw(); // Circle's Draw

s2.Draw(); // Rectangle's Draw

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details