Deck 13: Introduction to Classes
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/54
Play
Full screen (f)
Deck 13: Introduction to Classes
1
A destructor function can have zero to many parameters.
False
2
More than one constructor function may be defined for a class.
True
3
Constructor functions are often used to allocate memory that will be needed by the object.
True
4
While a class's member functions may be overloaded, the constructor cannot be overloaded.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
5
You must use the private access specification for all data members of a class.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
6
In OOP terminology, an object's member variables are often called its __________ and its member functions can be referred to as its behaviors or its __________.
A) values, morals
B) data, activities
C) attributes, activities
D) attributes, methods
E) None of these
A) values, morals
B) data, activities
C) attributes, activities
D) attributes, methods
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
7
More than one destructor function may be defined for a class.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
8
You must declare all data members of a class before you declare member functions.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
9
Class objects can be defined prior to the class declaration.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
10
In object-oriented programming, the object encapsulates both the data and the functions that operate on the data.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
11
In-place member initialization no longer is available in C++11.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
12
Whereas object-oriented programming centers on the object, procedural programming centers on functions.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
13
The constructor function may not accept arguments.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
14
If you do not declare a destructor function, the compiler will furnish one automatically.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
15
When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
16
Destructor functions are often used to free memory that was allocated by the object.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
17
You can use the technique known as a member intialization list to initialize members of a class.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
18
A private member function is useful for tasks that are internal to the class but it is not directly called by statements outside the class.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
19
Objects are created from abstract data types that encapsulate __________ and __________ together.
A) numbers, characters
B) data, functions
C) addresses, pointers
D) integers, floating-point numbers
E) None of these
A) numbers, characters
B) data, functions
C) addresses, pointers
D) integers, floating-point numbers
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
20
When using smart pointers to dynamically allocate objects in C++ 11, it is unnecessary to delete the dynamically allocated objects because the smart pointer will automatically delete them.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
21
When a constructor has a member initialization list, the initializations take place
A) after any statements in the body of the constructor execute
B) before any statements in the body of the constructor execute
C) when a member is used in the execution of the program
D) None of these
A) after any statements in the body of the constructor execute
B) before any statements in the body of the constructor execute
C) when a member is used in the execution of the program
D) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
22
Which type of member function may only be called from a function that is a member of the same class?
A) public
B) private
C) global
D) local
E) None of these
A) public
B) private
C) global
D) local
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
23
In C++11 you can use __________ to initialize a member variable in its declaration statement.
A) general member initialization
B) default initialization
C) in-place initialization
D) initialization overload
E) None of these
A) general member initialization
B) default initialization
C) in-place initialization
D) initialization overload
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
24
If you do not declare an access specification, the default for members of a class is
A) inline
B) private
C) public
D) global
E) None of these
A) inline
B) private
C) public
D) global
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
25
When the body of a member function is defined inside a class declaration, it is said to be
A) static
B) global
C) inline
D) conditional
E) None of these
A) static
B) global
C) inline
D) conditional
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
26
The type of member function that may be called from a statement outside the class is
A) public
B) private
C) undeclared
D) global
E) None of these
A) public
B) private
C) undeclared
D) global
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
27
A class is a(n) __________ that is defined by the programmer.
A) data type
B) function
C) method
D) attribute
E) None of these
A) data type
B) function
C) method
D) attribute
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
28
Where are class declarations usually stored?
A) on separate disk volumes
B) in their own header files
C) in .cpp files, along with function definitions
D) under pseudonyms
E) None of these
A) on separate disk volumes
B) in their own header files
C) in .cpp files, along with function definitions
D) under pseudonyms
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following is used to protect important data?
A) the public access specifier
B) the private access specifier
C) the protect member function
D) the class protection operator, @
E) None of these
A) the public access specifier
B) the private access specifier
C) the protect member function
D) the class protection operator, @
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
30
Members of the class object are accessed with the
A) dot operator
B) cin object
C) extraction operator
D) stream insertion operator
E) None of these
A) dot operator
B) cin object
C) extraction operator
D) stream insertion operator
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
31
A __________ is a member function that is automatically called when a class object is __________.
A) constructor, created
B) destructor, created
C) static function, deallocated
D) utility function, declared
E) None of these
A) constructor, created
B) destructor, created
C) static function, deallocated
D) utility function, declared
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
32
When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n)
A) empty constructor
B) default constructor
C) stand-alone function
D) arbitrator function
E) None of these
A) empty constructor
B) default constructor
C) stand-alone function
D) arbitrator function
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
33
In a procedural program you typically have __________ stored in a collection of variables and a set of __________ that perform operations on the data.
A) numbers, arguments
B) parameters, arguments
C) strings, operators
D) data, functions
E) None of these
A) numbers, arguments
B) parameters, arguments
C) strings, operators
D) data, functions
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
34
The destructor function's return type is
A) int
B) float
C) char
D) Nothing; destructors have no return type
E) None of these
A) int
B) float
C) char
D) Nothing; destructors have no return type
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
35
Examples of access specifiers are the key words
A) near and far
B) opened and closed
C) private and public
D) table and row
E) None of these
A) near and far
B) opened and closed
C) private and public
D) table and row
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
36
A C++ class is similar to a(n)
A) inline function
B) header file
C) library function
D) structure
E) None of these
A) inline function
B) header file
C) library function
D) structure
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following is a directive used to create an "include guard" that allows a program to be conditionally compiled to prevent a header file from accidentally being included more than once?
A) #include
B) #guard
C) #ifndef
D) #endif
E) None of these
A) #include
B) #guard
C) #ifndef
D) #endif
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
38
Assuming that Rectangle is a class name, what can you say is true, given the following statement?
Rectangle *BoxPtr;
A) The statement declares an object of the class Rectangle.
B) The statement assigns the value of *BoxPtr to the object Rectangle.
C) The statement defines a Rectangle pointer variable named *BoxPtr.
D) The statement is illegal in C++.
E) None of these
Rectangle *BoxPtr;
A) The statement declares an object of the class Rectangle.
B) The statement assigns the value of *BoxPtr to the object Rectangle.
C) The statement defines a Rectangle pointer variable named *BoxPtr.
D) The statement is illegal in C++.
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
39
When you dereference an object pointer, use the
A) -> operator
B) <> operator
C) dot operator
D) & operator
E) None of these
A) -> operator
B) <> operator
C) dot operator
D) & operator
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
40
The constructor function's return type is
A) int
B) float
C) char
D) structure pointer
E) None of these
A) int
B) float
C) char
D) structure pointer
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
41
For the following code, which statement is not true?
Class Point
{
Private:
Double y;
Double z;
Public:
Double x;
};
A) x is available to code that is written outside the class.
B) The name of the class is Point.
C) x, y, and z are called members of the class.
D) z is not available to code that is written outside the class.
E) All of these are true.
Class Point
{
Private:
Double y;
Double z;
Public:
Double x;
};
A) x is available to code that is written outside the class.
B) The name of the class is Point.
C) x, y, and z are called members of the class.
D) z is not available to code that is written outside the class.
E) All of these are true.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
42
What is the output of the following program?
#include
Using namespace std;
Class TestClass
{
Public:
TestClass(int x)
{ cout << x << endl; }
TestClass()
{ cout << "Hello!" << endl; }
};
Int main()
{
TestClass test(77);
Return 0;
}
A) the program runs but there is no output.
B) 77
C) Hello!
D) the program will not compile
#include
Using namespace std;
Class TestClass
{
Public:
TestClass(int x)
{ cout << x << endl; }
TestClass()
{ cout << "Hello!" << endl; }
};
Int main()
{
TestClass test(77);
Return 0;
}
A) the program runs but there is no output.
B) 77
C) Hello!
D) the program will not compile
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
43
How many default constructors can a class have?
A) only one
B) two or more
C) only two
D) any number
E) None of these
A) only one
B) two or more
C) only two
D) any number
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
44
The constructor function always has the same name as
A) the first private data member
B) the first public data member
C) the class
D) the first object of the class
E) None of these
A) the first private data member
B) the first public data member
C) the class
D) the first object of the class
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
45
If a local variable and a global variable have the same name within the same program, the __________ resolution operator must be used.
A) variable
B) ambiguity
C) scope
D) global
E) None of these
A) variable
B) ambiguity
C) scope
D) global
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
46
When a member function is defined outside of the class declaration, the function name must be qualified with the
A) class name, followed by a semicolon
B) name of the first object
C) class name, followed by the scope resolution operator
D) private access specifier
E) None of these
A) class name, followed by a semicolon
B) name of the first object
C) class name, followed by the scope resolution operator
D) private access specifier
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
47
The following code shows an example of __________ class Point
{
Private:
Double y = 5.70;
Double z = 3.0;
Public:
Public member functions go here...
};
A) constructor delegation
B) in-place initialization
C) a default constructor creation
D) an illegal initialization
{
Private:
Double y = 5.70;
Double z = 3.0;
Public:
Public member functions go here...
};
A) constructor delegation
B) in-place initialization
C) a default constructor creation
D) an illegal initialization
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
48
What is the output of the following program?
#include
Using namespace std;
Class TestClass
{
Private:
Int val;
Void showVal()
{ cout << val << endl; }
Public:
TestClass(int x)
{ val = x; }
};
Int main()
{
TestClass test(77);
Test.showVal();
Return 0;
}
A) the program runs but there is no output.
B) 77
C) 0
D) the program will not compile
#include
Using namespace std;
Class TestClass
{
Private:
Int val;
Void showVal()
{ cout << val << endl; }
Public:
TestClass(int x)
{ val = x; }
};
Int main()
{
TestClass test(77);
Test.showVal();
Return 0;
}
A) the program runs but there is no output.
B) 77
C) 0
D) the program will not compile
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
49
What is the output of the following program?
#include
Using namespace std;
Class TestClass
{
Public:
TestClass(int x)
{ cout << x << endl; }
TestClass()
{ cout << "Hello!" << endl; }
};
Int main()
{
TestClass test;
Return 0;
}
A) the program runs but there is no output.
B) 0
C) Hello!
D) the program will not compile
#include
Using namespace std;
Class TestClass
{
Public:
TestClass(int x)
{ cout << x << endl; }
TestClass()
{ cout << "Hello!" << endl; }
};
Int main()
{
TestClass test;
Return 0;
}
A) the program runs but there is no output.
B) 0
C) Hello!
D) the program will not compile
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
50
Which of the following is automatically called when an object is destroyed?
A) the constructor function
B) the specification deallocator
C) the destructor function
D) the destruction function
E) None of these
A) the constructor function
B) the specification deallocator
C) the destructor function
D) the destruction function
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
51
Assume that myCar is an instance of the Car class and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function?
A) Car -> accelerate();
B) myCar::accelerate();
C) myCar.accelerate();
D) myCar:accelerate();
E) None of these
A) Car -> accelerate();
B) myCar::accelerate();
C) myCar.accelerate();
D) myCar:accelerate();
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
52
Objects in an array are accessed with __________.
A) subscripts
B) parentheses
C) #include statements
D) output format manipulators
E) None of these
A) subscripts
B) parentheses
C) #include statements
D) output format manipulators
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
53
The process of object-oriented analysis can be viewed as the following steps:
A) identify objects, then define each object's attributes, behaviors, and relationships
B) define data members and member functions, then assign the class name
C) declare public and private variables, prototype functions, and then write code
D) write the main() function, then determine which classes are needed
E) None of these
A) identify objects, then define each object's attributes, behaviors, and relationships
B) define data members and member functions, then assign the class name
C) declare public and private variables, prototype functions, and then write code
D) write the main() function, then determine which classes are needed
E) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
54
In C++11 you can have one constructor call another constructor in the same class by using
A) constructor delegation
B) in-place initialization
C) a member initialization list
D) None of these
A) constructor delegation
B) in-place initialization
C) a member initialization list
D) None of these
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck