Inheritance
In C#, the specialization relationship is typically implemented using inheritance. This is not the only way to implement specialization, but it is the most common and most natural way to implement this relationship.
Saying that ListBox inherits from (or derives from) Control indicates that it specializes Control. Control is referred to as the base class, and ListBox is referred to as the derived class. That is, ListBox derives its characteristics and behaviors from Control, and then specializes to its own particular needs.
Implementing Inheritance
In C#, you create a derived class by adding a colon after the name of the derived class, followed by the name of the base class:
public class ListBox : Control
This code declares a new class, ListBox, which derives from Control. You can read the colon as "derives from."
Tip
C++ programmers take note: C# has no private or protected inheritance, and implements multiple inheritance only for interfaces, not for multiple base types. After eight years of C++ and now eight years of C#, I can honestly say that I see no disadvantage to this limitation.
The derived class inherits all the members of the base class, both member variables and methods.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access