#741 – The Basics of Inheritance
December 21, 2012 Leave a comment
Inheritance in C# (and .NET) is the idea of designing a class that reuses the implementation of an existing class. All public members in the original (parent) class become public members in the new (child) class. (Except for constructors). Both data and behavior are inherited by the child class.
Every class in C# must inherit from exactly one class. By default, a class inherits from System.Object. You can instead indicate the desired parent class by specifying it after a colon (:) when defining the new class.
public class Terrier : Dog { }
The class being inherited from is known as the base class or parent class. The new class is known as the derived class or child class.
An instance of the child class automatically has access to all public members of the base class, as well as its own public members.