Deck 7: Introduction to Classes and Objects
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/40
Play
Full screen (f)
Deck 7: Introduction to Classes and Objects
1
If Circle is the name of a class, which of the following statements would create a Circle object named myCircle?
A)Circle myCircle;
B)Circle myCircle();
C)myCircle Circle();
D)myCircle Circle;
E)None of the above
A)Circle myCircle;
B)Circle myCircle();
C)myCircle Circle();
D)myCircle Circle;
E)None of the above
A
2
A C++ member function that uses, but does not change, the value of a member variable is called
A)a constant.
B)a user.
C)a mutator.
D)an accessor.
E)a constructor.
A)a constant.
B)a user.
C)a mutator.
D)an accessor.
E)a constructor.
D
3
Objects permit data hiding. This means they can keep functions outside the class from
A)deleting the data.
B)knowing the names of the variables holding the data.
C)directly accessing the data.
D)changing the data.
E)doing all of the above.
A)deleting the data.
B)knowing the names of the variables holding the data.
C)directly accessing the data.
D)changing the data.
E)doing all of the above.
E
4
A class can have a member variable that is an instance of another class. This is called
A)object composition.
B)encapsulation.
C)object containment.
D)data hiding.
E)none of the above.
A)object composition.
B)encapsulation.
C)object containment.
D)data hiding.
E)none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
A C++ member function that sets or changes the value stored in a member variable is called
A)a user.
B)an updater.
C)a mutator.
D)an accessor.
E)a get function.
A)a user.
B)an updater.
C)a mutator.
D)an accessor.
E)a get function.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
Accessors are sometimes called _ functions and mutators are sometimes called functions.
A)get, set
B)private, public
C)regular, inline
D)public, private
E)set, get
A)get, set
B)private, public
C)regular, inline
D)public, private
E)set, get
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
In OOP terminology, an object's member variables are often called its , and its member functions are sometimes referred to as its .
A)values, operators
B)attributes, methods
C)data, activities
D)values, activities
E)attributes, activities
A)values, operators
B)attributes, methods
C)data, activities
D)values, activities
E)attributes, activities
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
The is used to protect important data.
A)protect()member function
B)private access specifier
C)class protection operator
D)public access specifier
E)default constructor
A)protect()member function
B)private access specifier
C)class protection operator
D)public access specifier
E)default constructor
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
A constructor may have a return type of
A)bool
B)void
C)int
D)any of the above.
E)none of the above.
A)bool
B)void
C)int
D)any of the above.
E)none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
Public members of a class object can be accessed from outside the class by using the
A)member access operator.
B)get function.
C)class name.
D)extraction operator.
E)dot operator.
A)member access operator.
B)get function.
C)class name.
D)extraction operator.
E)dot operator.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
ADT stands for _ Data Type.
A)Abstract
B)Automatic
C)Action
D)Algorithmic
E)None of the above
A)Abstract
B)Automatic
C)Action
D)Algorithmic
E)None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
The name of a destructor must begin with
A)a capital letter.
B)an underscore.
C)the name of the class.
D)a tilde (~).
E)none of the above.
A)a capital letter.
B)an underscore.
C)the name of the class.
D)a tilde (~).
E)none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
A destructor is a member function that
A)is automatically called when an object is destroyed.
B)is used to remove old unneeded objects.
C)causes the program to end.
D)can only be called by the main function of a program.
E)None of the above.
A)is automatically called when an object is destroyed.
B)is used to remove old unneeded objects.
C)causes the program to end.
D)can only be called by the main function of a program.
E)None of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
If setSide is a Square class function and box is a Square object, which of the following statements would set the length of box's side to 5?
A)setSide(5);
B)box.setSide(5);
C)Square(setSide(5));
D)Square.setSide(5);
E)None of the above
A)setSide(5);
B)box.setSide(5);
C)Square(setSide(5));
D)Square.setSide(5);
E)None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
When a constructor does not require that any arguments be passed to it, it is called a(n)_ constructor.
A)stand- alone
B)default
C)useless
D)empty
E)zero- element
A)stand- alone
B)default
C)useless
D)empty
E)zero- element
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
An object is a(n)_ of a class.
A)member
B)instance
C)example
D)copy
E)attribute
A)member
B)instance
C)example
D)copy
E)attribute
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
A structure variable is similar to a class object in which of the following ways?
A)It has member data that is usually private and accessed through public member functions.
B)It can be passed to a function or returned from a function.
C)Its data can be initialized with a constructor.
D)All of the above.
E)B and C, but not A.
A)It has member data that is usually private and accessed through public member functions.
B)It can be passed to a function or returned from a function.
C)Its data can be initialized with a constructor.
D)All of the above.
E)B and C, but not A.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
When an object or structure variable is passed to a function as a constant reference
A)the function accesses the original object, rather than a copy of it.
B)the function cannot make any changes to the member variables.
C)it is more efficient than passing it by value.
D)all of the above are true.
E)A and B are true, but not C.
A)the function accesses the original object, rather than a copy of it.
B)the function cannot make any changes to the member variables.
C)it is more efficient than passing it by value.
D)all of the above are true.
E)A and B are true, but not C.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
If Square is the name of a class, which of the following statements would create a Square object named box?
A)Square box();
B)Square box;
C)box Square();
D)box Square;
E)None of the above
A)Square box();
B)Square box;
C)box Square();
D)box Square;
E)None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
A constructor must have the same name as the
A)first object of the class.
B)function return type.
C)first private data member.
D)first public data member.
E)class.
A)first object of the class.
B)function return type.
C)first private data member.
D)first public data member.
E)class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
If employee is an instance of a class with 3 member variables (name, salary, and
department), the values of all three members will be output by the statement
cout << employee;
department), the values of all three members will be output by the statement
cout << employee;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
If setRadius is a Circle class function and myCircle is a Circle object, which of the following statements would set myCircle's radius to 2.5?
A)myCircle.setRadius(2.5);
B)setRadius(2.5);
C)Circle.setRadius(2.5);
D)Circle(setRadius(2.5));
E)None of the above
A)myCircle.setRadius(2.5);
B)setRadius(2.5);
C)Circle.setRadius(2.5);
D)Circle(setRadius(2.5));
E)None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
member function may be called by a statement in a function that is outside the class.
A)A public
B)A declared
C)Any
D)An inline
E)A private
A)A public
B)A declared
C)Any
D)An inline
E)A private
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
In C++ and other object- oriented programming languages, ADTs are normally implemented as classes.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
A constructor is a public class function that gets called whenever you want to re- initialize an object's member data.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
An Abstract data type (ADT)is a programmer- defined data type that specifies the values the type can hold, the operations that can be performed on them, and how the operations will be implemented.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
When three different objects of a particular class are created, they are said to be separate of the class.
A)members
B)instances
C)ADTs
D)children
E)None of the above
A)members
B)instances
C)ADTs
D)children
E)None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
Object- oriented programming is centered around objects that include both data and the functions that operate on them.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
The bundling of an object's data and procedures together is called
A)OOP.
B)private access.
C)encapsulation.
D)data hiding.
E)structuring.
A)OOP.
B)private access.
C)encapsulation.
D)data hiding.
E)structuring.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
A constructor is a public class function that is automatically invoked (i.e., called)whenever a class object is created.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
A class declaration provides a pattern for creating objects, so when a class is declared it automatically creates an object.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
A(n)member function may only be called from a function that is a member of the same class.
A)private
B)public
C)overloaded
D)local
E)constructor
A)private
B)public
C)overloaded
D)local
E)constructor
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
Objects can be passed to, and returned from, functions.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
In an ADT the implementation details are the interface through which a program uses it.
A)determined by
B)kept separate from
C)a part of
D)used by
E)None of the above
A)determined by
B)kept separate from
C)a part of
D)used by
E)None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
A structure has member variables, like an object, but they are usually all public and accessed directly with the dot operator, instead of by calling member functions.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
When a member function is defined outside of the class declaration, the function name must be qualified with the class name, followed by
A)the public access specifier.
B)the scope resolution operator (::).
C)a tilde (~).
D)a semicolon(;).
E)the private access specifier.
A)the public access specifier.
B)the scope resolution operator (::).
C)a tilde (~).
D)a semicolon(;).
E)the private access specifier.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
A class can only have one constructor.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
A class may have default constructor(s)and destructor(s).
A)more than one, only one
B)only one, only one
C)only one, more than one
D)no, only one
E)more than one, more than one
A)more than one, only one
B)only one, only one
C)only one, more than one
D)no, only one
E)more than one, more than one
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
When the body of a member function is defined inside a class declaration, it is called a(n)function.
A)conditional
B)constructor
C)static
D)inline
E)global
A)conditional
B)constructor
C)static
D)inline
E)global
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
A class declaration describes an object, but does not create any objects.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck