Inheritance and Polymorphism—Exercises
|Visual C# Tutorials|
|© 2006 O'Reilly Media, Inc.|
Exercise 11-1. Create a base class,
Telephone, and derive a class
Telephone, create a protected string member
phonetype, and a public method
Ring( ) that outputs a text message like this: "Ringing the <phonetype>." In
ElectronicPhone, the constructor should set the
phonetype to "Digital." In the
Ring( ) on the
ElectronicPhone to test the inheritance.
Exercise 11-2. Extend Exercise 11-1 to illustrate a polymorphic method. Have the derived class override the
Ring( ) method to display a different message.
Exercise 11-3. Change the
Telephone class to abstract, and make
Ring( ) an abstract method. Derive two new classes from
TalkingPhone. Each derived class should set the
phonetype, and override the
Ring( ) method.