← Back to C# Course | Chapter 7: Inheritance | Lesson 2 of 6

The base Keyword

In this page:

  1. The base Keyword

The base Keyword

base refers to the immediate parent class from inside a derived class, letting you call the base constructor or an overridden base method explicitly. base(args) in a constructor forwards initialization work to the parent. This avoids duplicating logic that the base class already handles.

Note: Use base.MethodName() inside an override when you want to extend, not replace, the parent's behavior.

Example: The base Keyword

markup
using System;

class Animal
{
    public string Name;

    public Animal(string name)
    {
        Name = name;
    }

    public virtual void Describe()
    {
        Console.WriteLine($"I am {Name}");
    }
}

class Dog : Animal
{
    public Dog(string name) : base(name) { }

    public override void Describe()
    {
        base.Describe();
        Console.WriteLine("...and I am a dog");
    }
}

class Program
{
    static void Main(string[] args)
    {
        Dog d = new Dog("Rex");
        d.Describe();
    }
}
🔒

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.