Is it possible for a member function of a class to activate another
member function of the same class?
- A. No.
- B. Yes, but only public member functions.
- C. Yes, but only private member functions.
- D. Yes, both public and private member functions can be
activated within another member function.
Can two classes contain member functions with the same name?
- A. No.
Yes, but only if the two classes have the same name.
Yes, but only if the main program does not declare both kinds
Yes, this is always allowed.
What is the common pattern of class definitions that is used in
Member functions and member variables are both private.
Member functions are private, and member variables are public.
Member functions are public, and member variables are private.
Member functions and member variables are both public.
Consider this class definition:
int f( );
int g( ) const;
Which functions can carry out an assignment
the private member variable
- A. Both f and g can carry out the assignment.
f can carry out the assignment, but not g.
g can carry out the assignment, but not f.
Neither f nor g can carry out the assignment.
What is the primary purpose of a default constructor?
To allow multiple classes to be used in a single program.
To copy an actual argument to a function's parameter.
To initialize each object as it is declared.
To maintain a count of how many objects of a class have been created.
Suppose that the foo class does not have an overloaded assignment
operator. What happens when an assignment
is given for two foo objects?
- A. The automatic assignment operator is used
- B. The copy constructor is used
- C. Compiler error
- D. Run-time error
When should you use a const reference parameter?
Classes and Parameters
- A. Whenever the data type might be many bytes.
- B. Whenever the data type might be many bytes, the function changes
the parameter within its body, and you do NOT want these changes
to alter the actual argument.
- C. Whenever the data type might be many bytes, the function changes
the parameter within its body, and you DO want these changes to
alter the actual argument.
- D. Whenever the data type might be many bytes, and the function does
not change the parameter within its body.
Here is a small function definition:
void f(int i, int &k)
i = 1;
k = 2;
Suppose that a main program has two integer variables x and y, which
are given the value 0. Then the main program calls
What are the values of x and y after the function f finishes?
- A. Both x and y are still 0.
- B. x is now 1, but y is still 0.
- C. x is still 0, but y is now 2.
- D. x is now 1, and y is now 2.
Here is a function prototype and some possible function calls:
int day_of_week(int year, int month = 1, int day = 1);
// Possible function calls:
cout << day_of_week( );
cout << day_of_week(1995);
cout << day_of_week(1995, 10);
cout << day_of_week(1995, 10, 4);
How many of the function calls are legal?
- A. None of them are legal
- B. 1 of them is legal
- C. 2 of them are legal
- D. 3 of them are legal
- E. All of them are legal
Which kind of functions can access private member variables of a class?
Operator Overloading and Friends
- A. Friend functions of the class
- B. Private member functions of the class
- C. Public member functions of the class
- D. All of the above can access private member variables
- E. None of the above