Section 11.10. Exercises


11.10. 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.



Learning C# 2005
Learning C# 2005: Get Started with C# 2.0 and .NET Programming (2nd Edition)
ISBN: 0596102097
EAN: 2147483647
Year: 2004
Pages: 250

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net