Chapter 17

 < Day Day Up > 



Chapter 16

  1. Describe in your own words what is meant by the term dynamic polymorphism.

    Dynamic polymorphism mean being able to treat different types of objects as if they were the same type using a uniform interface to those objects. A derived class object is substituted for and used where base class objects are specified.

  2. How does dynamic polymorphism differ from ad hoc and static polymorphism?

    Ad hoc polymorphism is operator overloading, meaning operators are given special functionality relevant to the context of a design.

    Static polymorphism is achieved by writing generic code that then can be used for different purposes based on the context of your design.

    Dynamic polymorphism enables you to substitute different implementation objects at runtime.

  3. What is a pure virtual function?

    A virtual function is a function that can be overridden by a derived class function having the same signature.

  4. How is a pure virtual function different from an ordinary virtual function?

    A pure virtual function has no implementation in the class or struct in which it is declared and must be overridden eventually in a derived class.

  5. A base class that declares one or more pure virtual functions is known as what type of class?

    Abstract base class

  6. What happens to a derived class if it inherits a pure virtual function but fails to override it?

    It becomes an abstract class.

  7. Describe the three different inheritance behaviors achieved through the use of pure virtual, ordinary virtual, and non-virtual functions.

    A class that declares pure virtual functions is serving as an interface specification only and provides no behavior. A derived class can either declare and implement the function or defer the implementation to yet another derived class down the inheritance chain.

    An ordinary virtual function provides some sort of behavior that will either be accepted by the derived class but can be overridden if desired.

    Non-virtual functions provide behavior and cannot be overridden in a derived class. However, they can be hidden by a redeclaration of a derived class member function with the same name.

  8. Consider the relationship between a base class and a derived class. What type of behavior should the base class implement as compared to the derived class's behavior?

    The base class should implement behavior that is common to all derived classes.

  9. How does public inheritance differ from private inheritance?

    Public inheritance means the derived class implements an 'is a' relationship.

    Private inheritance means there is no conceptual relationship between the base class and derived class since all public functions of the base class are now private in the derived class.

  10. What happens to public base class functions when a derived class privately inherits them?

    They become private in the derived class.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

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