Sams Teach Yourself C in 21 Days

(singke) #1
Answers for Bonus Day 3

Quiz


  1. A structure is a special form of the class in C++. The structure’s members are pub-
    lic by default. A class’ members are private by default. Note that, if you are using
    member functions, you should use a class instead of a structure.

  2. A class is only a definition, so you cannot assign values to it. You can use it to cre-
    ate an object. The object can have values assigned to it.

  3. An object is a variable that has been created using a class.

  4. To instantiate a class means to create an object using the class.

  5. Classes have characteristics from all three object-oriented features. Classes illus-
    trate encapsulation because they contain all the data and functionality in a single
    construct. Polymorphism can be seen in the fact that classes can have overlaid
    functions including their constructors. Inheritance is also a feature of classes.
    Bonus Day 4 will illustrate inheritance in more detail.

  6. A private data member can only be accessed from other data members within a
    class.

  7. A public data member can be accessed directly from any part when the object is in
    scope.

  8. A constructor is executed when an object is instantiated.

  9. A destructor is executed when an object is destroyed.

  10. A class isn’t different from using other types of data as a data member. You can use
    a class just as you can use an integer, character, structure, or any other data type.

  11. a. base class
    b. subclass
    c. neither the base class nor the subclass
    Theguppyis the subclass.

  12. a. base class
    b. subclass
    c. neither the base class nor the subclass
    Thefishis the base class.
    13.class guppy : public fish {

  13. The base class constructor executes first.

  14. The subclass destructor executes first.


876 Appendix F

49 448201x-APP F 8/13/02 11:22 AM Page 876

Free download pdf