Deck 7: Introduction to Classes and Objects

Full screen (f)
exit full mode
Question
Object-oriented programming is centered around objects that include both data and the functions that operate on them.
Use Space or
up arrow
down arrow
to flip the card.
Question
When the body of a member function is defined inside a class declaration, it is called a(n) ________ function.

A) static
B) global
C) inline
D) conditional
E) constructor
Question
A destructor is a member function that

A) is used to remove old unneeded objects.
B) causes the program to end.
C) is automatically called when an object is destroyed.
D) can only be called by the main function of a program.
E) None of the above.
Question
If Circle is the name of a class, which of the following statements would create a Circle object named myCircle?

A) myCircle Circle;
B) myCircle Circle();
C) Circle myCircle;
D) Circle myCircle();
E) None of the above
Question
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) data, activities
C) attributes, activities
D) attributes, methods
E) values, activities
Question
A(n) ________ member function may be called by a statement in a function that is outside of the class.

A) inline
B) public
C) private
D) declared
E) constructor
Question
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) setRadius(2.5);
B) myCircle.setRadius(2.5);
C) Circle.setRadius(2.5);
D) Circle(setRadius(2.5));
E) None of the above
Question
A C++ member function that uses, but does not change, the value of a member variable is called

A) an accessor.
B) a mutator.
C) a user.
D) a constant.
E) a constructor.
Question
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.
Question
A constructor that does not require that any arguments be passed to it is called a(n) ________ constructor.

A) empty
B) default
C) stand-alone
D) zero-element
E) useless
Question
A constructor may have a return type of

A) int
B) bool
C) void
D) any of the above.
E) none of the above.
Question
Which of the following statements about ADTs are True.

A) They specify the values the data type can hold.
B) They specify the operations the data type can perform.
C) They hide the details of how the data type is implemented.
D) They do all of the above.
E) They do A and B, but not C.
Question
A class declaration provides a pattern for creating objects, but doesn't make any objects.
Question
Which of the following statements correctly creates an enumerated data type and defines an object of that type.

A) enum Season = {"Spring", "Summer", "Fall", "Winter"} favoriteSeason;
B) enum Season = {Spring, Summer, Fall, Winter}, Season favoriteSeason;
C) enum Season {Spring, Summer, Fall, Winter}, enum favoriteSeason;
D) ENUM Season {Spring, Summer, Fall, Winter} favoriteSeason;
E) None of these
Question
ADT stands for Algorithmic Data Type.
Question
When three different objects of a class are created, they are said to be separate ________ of the class.

A) members
B) ADTs
C) instances
D) children
E) None of the above
Question
An object typically hides its data, but allows outside code to access it through its

A) private member functions.
B) public member functions.
C) public data members.
D) access specifiers.
E) None of the above
Question
A constructor is a public class function that is automatically invoked (i.e., called) whenever a class object is created.
Question
Accessors are sometimes called ________ functions and mutators are sometimes called ________ functions.

A) set, get
B) get, set
C) public, private
D) private, public
E) regular, inline
Question
A class must have exactly one constructor.
Question
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) Its data can be initialized with a constructor.
C) It can be passed to a function or returned from a function.
D) All of the above.
E) B and C, but not A.
Question
The bundling of an object's data and functions together is called

A) OOP.
B) encapsulation.
C) data hiding.
D) structuring.
E) private access.
Question
A constructor must have the same name as the

A) first private data member.
B) first public data member.
C) class.
D) first object of the class.
E) function return type.
Question
In C++ and other object-oriented programming languages, ADTs are normally implemented as classes.
Question
A class declaration creates an object.
Question
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.
Question
When a member function is defined outside of the class declaration, the function name must be qualified with the class name, followed by

A) a semicolon(;).
B) the scope resolution operator (::).
C) the public access specifier.
D) the private access specifier.
E) a tilde (~).
Question
A C++ member function that sets or changes the value stored in a member variable is called

A) an accessor.
B) a mutator.
C) a user.
D) a get function.
E) an updater.
Question
A class may have ________ default constructor(s) and ________ destructor(s).

A) only one, only one
B) only one, more than one
C) more than one, only one
D) more than one, more than one
E) no, only one
Question
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
Question
A class can have a member variable that is an instance of another class. This is called object nesting.
Question
A private member function may only be called from a function that is a member of the same class.
Question
An Abstract data type (AD
T) 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.
Question
An object is a(n) ________ of a class.

A) example
B) copy
C) instance
D) attribute
E) member
Question
The name of a destructor must begin with

A) the name of the class.
B) a tilde (~).
C) a capital letter.
D) an underscore.
E) none of the above.
Question
What will the following code segment display?
Enum Season {Spring, Summer, Fall, Winter} favoriteSeason;
FavoriteSeason = Summer;
Cout << favoriteSeason;

A) 1
B) 2
C) Summer
D) "Summer"
E) None of these.
Question
The ________ is used to protect important data.

A) default constructor
B) class protection operator
C) protect() member function
D) public access specifier
E) private access specifier
Question
A constructor is a public class function that gets called whenever you want to re-initialize an object's member data.
Question
If Square is the name of a class, which of the following statements would create a Square object named box?

A) box Square();
B) box Square;
C) Square box();
D) Square box;
E) None of the above
Question
Public members of a class object can be accessed from outside the class by using the

A) dot operator.
B) get function.
C) extraction operator.
D) member access operator.
E) class name.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 7: Introduction to Classes and Objects
1
Object-oriented programming is centered around objects that include both data and the functions that operate on them.
True
2
When the body of a member function is defined inside a class declaration, it is called a(n) ________ function.

A) static
B) global
C) inline
D) conditional
E) constructor
C
3
A destructor is a member function that

A) is used to remove old unneeded objects.
B) causes the program to end.
C) is automatically called when an object is destroyed.
D) can only be called by the main function of a program.
E) None of the above.
C
4
If Circle is the name of a class, which of the following statements would create a Circle object named myCircle?

A) myCircle Circle;
B) myCircle Circle();
C) Circle myCircle;
D) Circle myCircle();
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
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) data, activities
C) attributes, activities
D) attributes, methods
E) values, activities
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
A(n) ________ member function may be called by a statement in a function that is outside of the class.

A) inline
B) public
C) private
D) declared
E) constructor
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
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) setRadius(2.5);
B) myCircle.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
8
A C++ member function that uses, but does not change, the value of a member variable is called

A) an accessor.
B) a mutator.
C) a user.
D) a constant.
E) a constructor.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
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
10
A constructor that does not require that any arguments be passed to it is called a(n) ________ constructor.

A) empty
B) default
C) stand-alone
D) zero-element
E) useless
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
A constructor may have a return type of

A) int
B) bool
C) void
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
12
Which of the following statements about ADTs are True.

A) They specify the values the data type can hold.
B) They specify the operations the data type can perform.
C) They hide the details of how the data type is implemented.
D) They do all of the above.
E) They do A and B, but not C.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
A class declaration provides a pattern for creating objects, but doesn't make any objects.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following statements correctly creates an enumerated data type and defines an object of that type.

A) enum Season = {"Spring", "Summer", "Fall", "Winter"} favoriteSeason;
B) enum Season = {Spring, Summer, Fall, Winter}, Season favoriteSeason;
C) enum Season {Spring, Summer, Fall, Winter}, enum favoriteSeason;
D) ENUM Season {Spring, Summer, Fall, Winter} favoriteSeason;
E) None of these
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
ADT stands for Algorithmic Data Type.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
When three different objects of a class are created, they are said to be separate ________ of the class.

A) members
B) ADTs
C) instances
D) children
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
An object typically hides its data, but allows outside code to access it through its

A) private member functions.
B) public member functions.
C) public data members.
D) access specifiers.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
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
19
Accessors are sometimes called ________ functions and mutators are sometimes called ________ functions.

A) set, get
B) get, set
C) public, private
D) private, public
E) regular, inline
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
A class must have exactly one constructor.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
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) Its data can be initialized with a constructor.
C) It can be passed to a function or returned from a function.
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
22
The bundling of an object's data and functions together is called

A) OOP.
B) encapsulation.
C) data hiding.
D) structuring.
E) private access.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
A constructor must have the same name as the

A) first private data member.
B) first public data member.
C) class.
D) first object of the class.
E) function return type.
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 class declaration creates an object.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
When a member function is defined outside of the class declaration, the function name must be qualified with the class name, followed by

A) a semicolon(;).
B) the scope resolution operator (::).
C) the public access specifier.
D) the private access specifier.
E) a tilde (~).
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
A C++ member function that sets or changes the value stored in a member variable is called

A) an accessor.
B) a mutator.
C) a user.
D) a get function.
E) an updater.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
A class may have ________ default constructor(s) and ________ destructor(s).

A) only one, only one
B) only one, more than one
C) more than one, only one
D) more than one, more than one
E) no, only one
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
A class can have a member variable that is an instance of another class. This is called object nesting.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
A private member function may only be called from a function that is a member of the same class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
An Abstract data type (AD
T) 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
34
An object is a(n) ________ of a class.

A) example
B) copy
C) instance
D) attribute
E) member
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
The name of a destructor must begin with

A) the name of the class.
B) a tilde (~).
C) a capital letter.
D) an underscore.
E) none of the above.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
What will the following code segment display?
Enum Season {Spring, Summer, Fall, Winter} favoriteSeason;
FavoriteSeason = Summer;
Cout << favoriteSeason;

A) 1
B) 2
C) Summer
D) "Summer"
E) None of these.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
The ________ is used to protect important data.

A) default constructor
B) class protection operator
C) protect() member function
D) public access specifier
E) private access specifier
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
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
39
If Square is the name of a class, which of the following statements would create a Square object named box?

A) box Square();
B) box Square;
C) Square box();
D) Square box;
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
Public members of a class object can be accessed from outside the class by using the

A) dot operator.
B) get function.
C) extraction operator.
D) member access operator.
E) class name.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.