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

The base Keyword

The base keyword lets a child class talk to its parent, like asking mom how she did something. It reaches the parent's version of a method or constructor.

In this page:

  1. The base Keyword
Syntax
csharp
class DerivedClass : BaseClass
{
    public DerivedClass(type parameter) : base(parameter)   // call the base constructor
    {
    }

    public override void MethodName()
    {
        base.MethodName();   // call the base version
    }
}

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();
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Forgetting to call the base constructor with the right arguments when the base class has no default constructor.
  2. Using base in a static method, where it is not available.
  3. Calling base.Method() for a method that is abstract, which is a compile error.
🔒

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.