← Back to C# Course | Chapter 8: Interfaces | Lesson 1 of 6

Interface Basics

In this page:

  1. Interface Basics

Interface Basics

An interface declares a contract of members that implementing classes must provide, but supplies no implementation of its own (aside from default methods). It's declared with interface and conventionally named starting with I, like IShape. Interfaces define *what* a type can do, not *how* it does it.

Note: Interface members are implicitly public — you never write an access modifier on them.

Example: Interface Basics

markup
using System;

interface IGreeter
{
    void Greet();
}

class EnglishGreeter : IGreeter
{
    public void Greet()
    {
        Console.WriteLine("Hello!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        IGreeter g = new EnglishGreeter();
        g.Greet();
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.