October 2008
Beginner to intermediate
680 pages
16h 48m
English
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, ...Read now
Unlock full access