Junior OOP

What is the role of interfaces in achieving polymorphism?

  • Interfaces allow different classes to implement the same contract, enabling

dynamic behavior at runtime.

interface IDriveable { void Drive(); }

class Car : IDriveable { public void Drive() =>

Console.WriteLine("Car drives"); }

class Bike : IDriveable { public void Drive() =>

Console.WriteLine("Bike drives"); }

More from C# Programming Tutorial

All questions for this course