Inheritance Fundamentals

The basic syntax for deriving a class from a base class is shown in Syntax Box 16.1. We write the class header of the derived class as usual by specifying any optional modifiers followed by the class keyword and the classname. The different and important bit in this context is the semicolon (:) followed by the name of the class we want as a base class for the derived class. The meaning of the semicolon could consequently be “is derived from.”

Syntax Box 16.1 Class Definition with Optional Derivation

						Class_definition_with optional_derivation::=
						[<Access_modifier>] class <Derived_class_name> [ : <Base_class_name>]
{
    <Class_members_of_derived_class>
}

Note:

The colon followed by the base classname (: <Base_class_name> ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.