Exercises

Exercise 11-1

Create a base class, Telephone, and derive a class ElectronicPhone from it. In 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 Run( ) method, call 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 Telephone: DigitalPhone and TalkingPhone. Each derived class should set the phonetype, and override the Ring( ) method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset