Deck 11: More About Classes and Object-Oriented Programming
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/70
Play
Full screen (f)
Deck 11: More About Classes and Object-Oriented Programming
1
C++ permits you to overload the sizeof operator.
False
2
A reason to overload the ________ is to write classes that have array-like behavior.
A) parentheses ( )
B) curly braces { }
C) square brackets [ ]
D) colon : :
E) None of the above
A) parentheses ( )
B) curly braces { }
C) square brackets [ ]
D) colon : :
E) None of the above
C
3
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.
False
4
C++ requires that a copy constructor's parameter be
A) an integer data type.
B) a floating-point data type.
C) a pointer variable.
D) a reference to an object.
E) None of the above
A) an integer data type.
B) a floating-point data type.
C) a pointer variable.
D) a reference to an object.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
5
When a class contains a pointer to dynamically allocated memory, it a good idea to have the class overload the assignment operator.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
6
Each object of a class has its own copy of the class's
A) static member variables.
B) instance member variables.
C) static member functions.
D) All of the above
E) None of the above
A) static member variables.
B) instance member variables.
C) static member functions.
D) All of the above
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
7
A good reason for overloading an operator is to enable it to
A) outperform its C language counterparts.
B) be used with types defined by the programmer.
C) operate on more operands than in its standard definition.
D) operate on no operands.
E) None of the above
A) outperform its C language counterparts.
B) be used with types defined by the programmer.
C) operate on more operands than in its standard definition.
D) operate on no operands.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
8
The ________ operator may be used to assign one object to another.
A) =
B) ==
C) <>
D) &
E) None of the above
A) =
B) ==
C) <>
D) &
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
9
You can overload the conditional operator to make it function as an unconditional operator.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
10
If a function f is a friend of a class A, and the class A is a friend of a class B, then the function f is able to access private members of B.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
11
A static member variable can be used when there are no objects of the class in existence.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
12
By default, when an object is assigned to another, each member of one object is copied to its counterpart in the other object.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
13
When a class contains a pointer to dynamically allocated memory, it is a good idea to equip the class with
A) a dynamically allocated constructor.
B) a copy constructor.
C) a static constructor and an overloaded comparison operator.
D) an inline constructor.
E) None of the above
A) a dynamically allocated constructor.
B) a copy constructor.
C) a static constructor and an overloaded comparison operator.
D) an inline constructor.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
14
If you do not furnish a(n) ________, 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 the above
A) overloaded constructor function
B) overloaded assignment operator
C) default constructor function
D) overloaded copy operator
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
15
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, glob
E) None of the above
A) inline, inline
B) static, static
C) constant, const
D) global, glob
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
16
The process of having a class contain an instance of another class is known as
A) object overloading.
B) operator overloading.
C) object composition.
D) dynamic composition.
E) None of the above
A) object overloading.
B) operator overloading.
C) object composition.
D) dynamic composition.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
17
If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded also.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
18
When you overload the << operator, you must also overload the >> operator.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
19
C++ allows you to overload
A) compiler errors.
B) preprocessor directives.
C) operators and functions.
D) undefined variables.
E) None of the above
A) compiler errors.
B) preprocessor directives.
C) operators and functions.
D) undefined variables.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
20
A(n) ________ member variable may be accessed before any objects of the class have been declared.
A) private
B) public
C) inline
D) static
E) None of the above
A) private
B) public
C) inline
D) static
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
21
A member function that is declared ________ cannot use the this pointer.
A) private
B) public
C) static
D) inline
E) None of the above
A) private
B) public
C) static
D) inline
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
22
If a member variable is declared ________, all objects of that class share access to that variable.
A) static
B) dynamic
C) inline
D) default
E) None of the above
A) static
B) dynamic
C) inline
D) default
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
23
A lambda expression is
A) an expression whose value can only be assigned to a local variable.
B) used by the C++ compiler to check the types of other expressions.
C) a class derived from a function object.
D) an object of a class whose only member is the function call operator.
E) None of the above
A) an expression whose value can only be assigned to a local variable.
B) used by the C++ compiler to check the types of other expressions.
C) a class derived from a function object.
D) an object of a class whose only member is the function call operator.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
24
The library function move() can be used to
A) transfer ownership of a managed object from one unique_ptr object to another.
B) move the contents of a dynamically allocated block of memory to another address.
C) move the contents of any block of memory to another address.
D) make a raw pointer point to a different memory location.
A) transfer ownership of a managed object from one unique_ptr object to another.
B) move the contents of a dynamically allocated block of memory to another address.
C) move the contents of any block of memory to another address.
D) make a raw pointer point to a different memory location.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
25
If an rvalue reference refers to a memory location, that memory location becomes an lvalue.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
26
________ members of a base class are never accessible to a derived class.
A) Public
B) Private
C) Protected
D) A, B, and C
E) None of the above
A) Public
B) Private
C) Protected
D) A, B, and C
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
27
A member function of a derived class may not have the same name as a member function of a base class.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
28
When you derive a class from an existing class, you
A) can add new data, but cannot add new functions.
B) can add new functions, but cannot add new data.
C) can add both new data and new functions.
D) must add both new data and new functions.
E) None of the above
A) can add new data, but cannot add new functions.
B) can add new functions, but cannot add new data.
C) can add both new data and new functions.
D) must add both new data and new functions.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
29
________ allows us to create new classes based on existing classes.
A) Polymorphism
B) Inheritance
C) Function overloading
D) The copy constructor
E) None of the above
A) Polymorphism
B) Inheritance
C) Function overloading
D) The copy constructor
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
30
It is possible to declare an entire class as a friend of another class.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
31
A derived class may become a base class, if another class is derived from it.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
32
Some C++ operators cannot be overloaded by the programmer.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
33
A ________ 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 the above
A) static
B) constructor
C) destructor
D) friend
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
34
The ________ class constructor is called before the ________ class constructor.
A) base, derived
B) derived, base
C) public, private
D) private, public
E) None of the above
A) base, derived
B) derived, base
C) public, private
D) private, public
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
35
A derived class may not have any classes derived from it.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
36
In the statement class Car:public Vehicle, which is the base class?
A) Car
B) Vehicle
C) public
D) class
E) None of the above
A) Car
B) Vehicle
C) public
D) class
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
37
In an inheritance situation, you can't pass arguments to a base class constructor.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
38
A situation in which every object of a class A has a pointer to an object of a class B, and the objects of the class B may outlive objects of class A, is called
A) a has-A relation.
B) aggregation.
C) composition.
D) an is=A relation.
E) None of the above
A) a has-A relation.
B) aggregation.
C) composition.
D) an is=A relation.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
39
Arguments are passed to the base class destructor function by the ________ class ________ function.
A) derived, constructor
B) derived, destructor
C) base, constructor
D) base, destructor
E) None of the above
A) derived, constructor
B) derived, destructor
C) base, constructor
D) base, destructor
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
40
A static member function can be called independently of any object of the class.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
41
In an inheritance situation, the new class that you create from an existing class is known as the
A) derived class.
B) inheritee.
C) child class.
D) both A and C
E) None of the above
A) derived class.
B) inheritee.
C) child class.
D) both A and C
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
42
To overload the + operator, you would write a function called
A) overload +.
B) operator +.
C) function +.
D) operator.overload(+).
E) None of the above
A) overload +.
B) operator +.
C) function +.
D) operator.overload(+).
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
43
A(n) ________ is a special function that is called whenever a new object is created and initialized with data from another object of the same class.
A) destructor
B) static function
C) copy constructor
D) assignment function
E) None of the above
A) destructor
B) static function
C) copy constructor
D) assignment function
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
44
In C++, if you overload the < operator, you must also overload the > operator.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
45
The this pointer is automatically passed to static member functions of a class.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
46
If you do not furnish a(n) ________ for a class, a default will be provided for you by the compiler.
A) copy constructor
B) constructor
C) assignment operator
D) All of the above
E) None of the above
A) copy constructor
B) constructor
C) assignment operator
D) All of the above
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
47
A constructor that takes a single parameter of a type other than its class is called a convert constructor.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
48
When overloading the operator ++, ________ is used to distinguish preincrement from postincrement.
A) a parameterless data type
B) the keyword void
C) a dummy integer parameter
D) the placeholder [ ]
E) None of the above
A) a parameterless data type
B) the keyword void
C) a dummy integer parameter
D) the placeholder [ ]
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
49
Object composition is useful for creating a ________ relationship between classes.
A) friend
B) static
C) has-a
D) conditional
E) None of the above
A) friend
B) static
C) has-a
D) conditional
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
50
The base class's ________ affects the way its members are inherited by the derived class.
A) name
B) return data type
C) access specification
D) both A and B
E) None of the above
A) name
B) return data type
C) access specification
D) both A and B
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
51
You may overload any C++ operator, and you may use the operator function to define non-standard operators, such as @ and ^.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
52
A static member function cannot be called if no objects of the class exist.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
53
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 the above
A) reassigned
B) reformatted
C) overloaded
D) overwhelmed
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
54
An ________ operator can work with programmer-defined data types.
A) inline
B) unconditional
C) overloaded
D) undefined
E) None of the above
A) inline
B) unconditional
C) overloaded
D) undefined
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
55
Protected members of a base class are like ________, with the exception that they may be accessed by derived classes.
A) constructor functions
B) static members
C) private members
D) public members
E) None of the above
A) constructor functions
B) static members
C) private members
D) public members
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
56
When you overload an operator, you cannot change the number of operands taken by the operator.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
57
The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all instance member functions.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
58
The structure member selector operator . cannot be overloaded.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
59
To dereference an object pointer and access one of the object's members, use the
A) -> operator.
B) <> operator.
C) dot operator.
D) & operator.
E) None of the above
A) -> operator.
B) <> operator.
C) dot operator.
D) & operator.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
60
The ________ is a special built-in pointer that is available to a class's instance member functions.
A) overloaded -> operator
B) this pointer
C) &constructor pointer
D) ~destructor *ptr
E) None of the above
A) overloaded -> operator
B) this pointer
C) &constructor pointer
D) ~destructor *ptr
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
61
The base class access specification can be viewed as a filter that base class members must pass through when becoming inherited members of a derived class.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
62
In the statement class Car:protected Vehicle, which is the derived class?
A) Car
B) Vehicle
C) protected
D) The answer cannot be determined from the information given.
E) None of the above
A) Car
B) Vehicle
C) protected
D) The answer cannot be determined from the information given.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
63
In the statement class Car:protected Vehicle, what is being protected?
A) Derived class functions
B) Base class members
C) Derived class data
D) Future inherited classes
E) None of the above
A) Derived class functions
B) Base class members
C) Derived class data
D) Future inherited classes
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
64
An lvalue is
A) a value of type long.
B) a memory location that is associated with a name that can be used by different parts of the program to access the memory location.
C) An expression denoting a value that appears as the left operand of a binary operator.
D) a value of type long returned from a function.
E) None of the above
A) a value of type long.
B) a memory location that is associated with a name that can be used by different parts of the program to access the memory location.
C) An expression denoting a value that appears as the left operand of a binary operator.
D) a value of type long returned from a function.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
65
________ is commonly used to extend a class, or to give it additional capabilities.
A) Inheritance
B) Privacy
C) The constructor
D) The destructor
E) None of the above
A) Inheritance
B) Privacy
C) The constructor
D) The destructor
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
66
A base class cannot contain a pointer to one of its derived classes.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
67
A function object is
A) an instance of a class that has exactly one member function and no member variables.
B) an object of a class that has any number of member functions, but no member variables.
C) an object of a class that overloads the function call operator ().
D) an object that has a member variable that is a pointer to a function.
E) None of the above
A) an instance of a class that has exactly one member function and no member variables.
B) an object of a class that has any number of member functions, but no member variables.
C) an object of a class that overloads the function call operator ().
D) an object that has a member variable that is a pointer to a function.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
68
When arguments must be passed to the base class constructor, they are passed from the derived class constructor's header line.
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
69
The ________ class destructor is called before the ________ class destructor.
A) base, derived
B) derived, base
C) public, private
D) private, public
E) None of the above
A) base, derived
B) derived, base
C) public, private
D) private, public
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck
70
An rvalue is
A) a temporary value that cannot be accessed from a different part of the program.
B) the right operand of a binary operator.
C) a value passed as the rightmost parameter of a function.
D) a memory location that is associated with a name that can be used by different parts of the program to access the memory location.
E) None of the above
A) a temporary value that cannot be accessed from a different part of the program.
B) the right operand of a binary operator.
C) a value passed as the rightmost parameter of a function.
D) a memory location that is associated with a name that can be used by different parts of the program to access the memory location.
E) None of the above
Unlock Deck
Unlock for access to all 70 flashcards in this deck.
Unlock Deck
k this deck