Chapter 14 Starting out with C++ More About Classes
Download file with the answers
Chapter 14 Starting out with C++ More About Classes
1 file(s) 81.03 KB
Not a member!
Create a FREE account here to get access and download this file with answers
Chapter Fourteen
MULTIPLE CHOICE
1. Each object of a class has its own copy of the class’s
a. member functions
b. member variables
c. constructor and destructor functions
d. All of these
e. None of these
2. This type of member variable may be accessed before any objects of the class have been created.
a. private
b. public
c. inline
d. static
e. None of these
3. This operator may be used to assign one object to another.
a. =
b. ==
c. <>
d. @
e. None of these
4. C++ requires that a copy constructor’s parameter be a(n)
a. integer data type
b. floating point data type
c. pointer variable
d. reference object
e. None of these
5. C++ allows you to redefine the way ____________ work when used with class objects.
a. compiler errors
b. preprocessor directives
c. standard operators
d. undefined variables
e. None of these
6. When objects contain pointers, it is a good idea to create an explicit ________ function.
a. destructor
b. copy constructor
c. static constructor
d. inline constructor
e. None of these
7. A good reason for overloading an operator is to enable it to:
a. outperform its C language counterparts
b. work in its usual way, but with programmer-defined data types
c. operate on more operands than in its standard definition
d. operate on no operands
e. None of these
8. When a class contains an instance of another class, it is known as
a. object overloading
b. operator overloading
c. object composition
d. dynamic composition
e. None of these
9. If you do not furnish one of these, an automatic memberwise copy will be performed when one object is assigned to another object.
a. overloaded constructor function
b. overloaded assignment operator
c. default constructor function
d. overloaded copy operator
e. None of these
10. It is a good idea to make a copy constructor’s parameters __________ by specifying the _________ keyword in the parameter list.
a. inline, inline
b. static, static
c. constant, const
d. global, global
e. None of these
11. A reason to overload the ____________ is to write classes that have array-like behaviors.
a. parentheses ( ) operator
b. curly braces { } operator
c. square brackets [ ] operator
d. colon : : operator
e. None of these
12. If a member variable is declared ____________, all objects of that class have access to that variable.
a. static
b. dynamic
c. inline
d. default
e. None of these
13. A member function that is declared _____________ may not access any non-static data members in the class.
a. private
b. public
c. static
d. inline
e. None of these
14. This type of function is not a member of a class, but it has access to the private members of the class.
a. static
b. constructor
c. destructor
d. friend
e. None of these
15. This is a special function that is called whenever a new object is created and initialized with another object’s data.
a. destructor
b. static function
c. copy constructor
d. assignment function
e. None of these
16. If you do not furnish one of these a default will be provided for you by the compiler.
a. copy constructor
b. constructor
c. destructor
d. All of these
e. None of these
17. When you redefine the way a standard operator works when it is used with class objects, you have ____________ the operator.
a. reassigned
b. reformatted
c. overloaded
d. overwhelmed
e. None of these
18. To overload the + operator, you would write a function named:
a. overload +
b. operator +
c. function +
d. operator.overload(+)
e. None of these
19. This is a special built-in pointer that is available to a class’s member functions.
a. overloaded -> operator
b. this pointer
c. &constructor pointer
d. ~destructor *ptr
e. None of these
20. Object composition is useful for creating this type of relationship between classes.
a. friend
b. static
c. has a
d. conditional
e. None of these
21. A(n) ________ operator can work with programmer-defined data types.
a. inline
b. unconditional
c. overloaded
d. undefined
e. None of these
22. When you overload an operator, you cannot change the number of ________ taken by the operator.
a. arguments
b. parameters
c. operations
d. operands
e. None of these
23. A(n) ___________ informs the compiler that a class will be declared later in the program.
a. static function
b. private data member
c. forward declaration
d. object conversion
e. None of these
24. In the following function header,
FeetInches FeetInches::operator++(int)
the word (int) is known as a:
a. parameterless data type
b. incomplete argument
c. dummy parameter
d. incomplete parameter
e. None of these
TRUE/FALSE
1. True/False: When a class declares an entire class as its friend, the friendship status is reciprocal. That is, each class’s member functions have free access to the other’s private members.
2. True/False: By default, when an object is assigned to another, each member of one object is copied to its counterpart in the other object.
3. True/False: When you overload an operator, you can change the operator’s original meaning to something entirely different.
4. True/False: If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded.
5. True/False: A public data member may be declared a friend of a private function.
6. True/False: C++ permits you to overload the sizeof operator and the this pointer.
7. True/False: A static member variable can be used when there are no objects of the class in existence.
8. True/False: When you overload the << operator, you must also overload the >> operator.
9. True/False: You can overload the conditional operator to make it function as an unconditional operator.
10. True/False: A static member function does not need to be called by a specific object of the class.
11. True/False: It is possible to declare an entire class as a friend of another class.
12. True/False: You may overload any C++ operator, and you may use the operator function to define non-standard operators, such as @ and ^.
13. True/False: The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all non-static member functions.
14. True/False: In C++, if you overload the < operator, you must also overload the > operator.
15. True/False: A non-static member function may not access a static member variable.
16. True/False: The this pointer is automatically passed to non-static member functions of a class.
Leave a reply