13.10. More About Inheritance and C#

From our discussion of inheritance in Chapter 5, we learned that

  • Inheritance is used to derive a new class definition from an existing class when the new class is perceived to be a special case of the existing class.

  • The derived class automatically inherits the data structure and behaviors of the base class.

  • C# uses a colon followed by a class name in a class declaration to signal that one class is derived from another:

    public class Person
    {
      private string name;
    
      public string Name {
        get {
          return name;
        }
        set {
          name = value;
        }
      }
    }
    
    // We derive the Student class from Person.
    							public class Student : Person { // If we define nothing in the body of this class, it will still // have one field, name, and one property, ...

Get Beginning C# 2008 Objects: From Concept to Code now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.