C# VS2026
Lesson 18 of 30

OOP – Interfaces and Abstract Classes

C# in Visual Studio 2026 — a hands-on guide for developers at every level.

Interfaces

An interface defines a contract — a set of method, property, and event signatures that a class must implement. A class can implement multiple interfaces.

public interface IShape
{
    double Area();
    double Perimeter();
    string Describe() => $"Area={Area():F2}, P={Perimeter():F2}";  // default impl
}

public class Circle : IShape
{
    public double Radius { get; }
    public Circle(double r) => Radius = r;
    public double Area()      => Math.PI * Radius * Radius;
    public double Perimeter() => 2 * Math.PI * Radius;
}

public class Rectangle : IShape
{
    public double W { get; } public double H { get; }
    public Rectangle(double w, double h) { W = w; H = h; }
    public double Area()      => W * H;
    public double Perimeter() => 2 * (W + H);
}

IShape[] shapes = { new Circle(5), new Rectangle(4, 6) };
foreach (var s in shapes)
    Console.WriteLine(s.Describe());

Abstract Classes

An abstract class provides partial implementation. You cannot instantiate it directly.

public abstract class Vehicle
{
    public string Make { get; }
    protected Vehicle(string make) => Make = make;
    public abstract void Drive();  // must override
    public virtual void Stop() => Console.WriteLine("Stopping.");
}

public class Car : Vehicle
{
    public Car(string make) : base(make) { }
    public override void Drive() => Console.WriteLine($"{Make} driving on road");
}