Chapter 18 – C How to Program 6e Multiple Choice Test Bank
Download file with the answers
Chapter 18 - C How to Program 6e Multiple Choice Test Bank
1 file(s) 177.83 KB
Not a member!
Create a FREE account here to get access and download this file with answers
Chapter 18: Classes: A Deeper Look, Part 2
Section 18.2 const (Constant) Objects and const Member Functions
18.2 Q1: Which of the following statements will not produce a syntax error?
a. Defining a const member function that modifies a data member of the object.
b. Invoking a non-const member function on a const object.
c. Declaring an object to be const.
d. Declaring a constructor to be const.
18.2 Q2: The code fragment:
Increment::Increment( int c, int i )
: increment ( i )
{
count = c;
}
does not cause any compilation errors. This tells you that:
a. count must be a non-const variable.
b. count must be a const variable.
c. increment must be a non-const variable.
d. increment must be a const variable.
Section 18.3 Composition: Objects as Members of Classes
18.3 Q1: When composition (one object having another object as a member) is used:
a. The host object is constructed first and then the member objects are placed into it.
b. Member objects are constructed first, in the order they appear in the host constructor’s initializer list.
c. Member objects are constructed first, in the order they are declared in the host’s class.
d. Member objects are destructed last, in the order they are declared in the host’s class.
18.3 Q2: An error occurs if:
a. A non-reference, non-const, primitive data member is initialized in the member initialization list.
b. An object data member is not initialized in the member initialization list.
c. An object data member does not have a default constructor.
d. An object data member is not initialized in the member initialization list and does not have a default constructor.
Section 18.4 friend Functions and friend Classes
18.4 Q1: If the line:
friend class A;
appears in class B, and the line:
friend class B;
appears in class C, then:
a. Class A is a friend of class C.
b. Class A can access private variables of class B.
c. Class C can call class A’s private member functions.
d. Class B can access class A’s private variables.
18.4 Q2: Which of the following statements about friend functions and friend classes is false?
a. A class can either grant friendship to or take friendship from another class using the friend keyword.
b. A friend declaration can appear anywhere in a class definition.
c. A friend of a class can access all of its private data member and member functions.
d. The friendship relationship is neither symmetric nor transitive.
Section 18.5 Using the this Pointer
18.5 Q1: For a non-constant member function of class Test, the this pointer has type:
a. const Test *
b. Test * const
c. Test const *
d. const Test * const
18.5 Q2: Inside a function definition for a member function of an object with data element x, which of the following is not equivalent to this->x:
a. *this.x
b. (*this).x
c. x
d. (* (& (*this) ) ).x
18.5 Q3: Assume that t is an object of class Test, which has member functions a(), b(), c() and d(). If the functions a(), b() and c() all return references to an object of class Test (using the dereferenced this pointer) and function d() returns void, which of the following statements will not produce a syntax error:
a. t.a().b().d();
b. a().b().t;
c. t.d().c();
d. t.a().t.d();
Section 18.6 static Class Members
18.6 Q1: If Americans are objects of the same class, which of the following attributes would most likely be represented by a static variable of that class?
a. Age.
b. The President.
c. Place of birth.
d. Favorite food.
18.6 Q2: static data members of a certain class:
a. Can be accessed only if an object of that class exists.
b. Cannot be changed, even by objects of the same that class.
c. Have class scope.
d. Can only be changed by static member functions.
18.6 Q3: static member functions:
a. Can use the this pointer.
b. Can access only other static member functions and static data members.
c. Cannot be called until an object of their class is instantiated.
d. Can be declared const as well.
Section 18.7 Proxy Classes
18.7 Q1: Proxy classes are best described as an example of:
a. Object-oriented programming (as used in the text).
b. Structured programming.
c. Information hiding.
d. Utility functions.
18.7 Q2: In addition to hiding the implementation details that the ordinary method of “separating implementation from interface” would hide, using a proxy class also hides:
a. The definition of inline functions.
b. The definition of access functions.
c. The definition of constructors and the destructor.
d. The names of private data members.
Leave a reply