#741 – The Basics of Inheritance

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.


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: