Skip to content
Justice Tech School

C# Interfaces and Abstract Classes

An interface lists members a class must provide, and a class can implement many. An abstract class cannot be instantiated and may hold shared code.

Example
interface IShape { double Area(); }
class Circle : IShape { public double R; public double Area() => Math.PI * R * R; }
class Square : IShape { public double S; public double Area() => S * S; }
IShape[] shapes = { new Circle { R = 1 }, new Square { S = 2 } };
foreach (var s in shapes) Console.WriteLine(Math.Round(s.Area(), 2));

Exercise

Interface name starts with.

interface Shape

Quiz Test

How many interfaces can a class implement?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.