Chapter 4. Inheritance

Chapter 3, "Objects and Types," examined how to use individual classes in C#. The focus in that chapter was on how to define methods, constructors, properties, and other members of a single class (or a single struct). Although you did learn that all classes ultimately derive from the class System.Object, you did not see how to create a hierarchy of inherited classes. Inheritance is the subject of this chapter. It briefly discusses the scope of C#'s support for inheritance before examining in detail how to code first implementation inheritance and then interface inheritance in C#. Note that this chapter presumes familiarity with the basic concepts of inheritance, including virtual functions and overriding. This chapter concentrates on the syntax used to provide inheritance and inheritance-related topics, such as virtual functions, and on those aspects of the C# inheritance model that are particular to C# and not necessarily shared by other object-oriented languages.

Types of Inheritance

This chapter starts off by reviewing exactly what C# does and does not support as far as inheritance is concerned.

Implementation Versus Interface Inheritance

Gurus of object-oriented programming will know that there are two distinct types of inheritance: implementation inheritance and interface inheritance.

  • Implementation inheritance means that a type derives from a base type, taking all the base type's member fields and functions. With implementation inheritance, a derived type ...

Get Professional C# 2005 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.