Introduction to Inheritance
The primary characteristic of the objects on the above pictures is that they are balls used in
different sports. Another characteristic they share is that they are round. On the other hand,
although these balls are used in sport, one made for one sport cannot (or should not) be used
in another sport (of course, it is not unusual for a footballer to mess with a basketball on a
lawn but it is not appropriate). The common characteristics of these objects can be listed in a
group like a C# class. The class would appear as:
If you were asked to create a class to represent these balls, you may be tempted to implement
a general class that defines each ball. This may be a bad idea because, despite their round
resemblance, there are many internal differences among these balls. Programming languages
like C# provide an alternate solution to this type of situation.
Inheritance consists of creating a class whose primary definition or behavior is based on
another class. In other words, inheritance starts by having a class that can provide behavior
that other classes can improve on.
1. Start Microsoft Visual C# 2005 Express Edition and create a new Console Application named
2. To create a new class, in the Class View, right-click the name of the project, position the mouse
on Add and click Class...
3. Set the Name to Property and press Enter
4. Change the file as follows:
Practical Learning: Introducing Inheritance
Generated by www.PDFonFly.com at 12/15/2009 10:33:05 PM
5. To create a new class, in the Solution Explorer, right-click the name of the project, position the
public enum PropertyCondition