Chapter 13 - COSC
Members of the class object are accessed with the __.
dot operator
Where are class declarations usually stored?
in their own header files
Objects in an array are accessed with ________.
subtricts
The constructor function always has the same name as
the class
Which of the following is automatically called when an object is destroyed?
the destructor function
Which of the following is used to protect important data?
the private access specifier
What is the output of the following program? #include <iostream> 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; }
the program will not compile
For the following code, which statement is NOT true? class Point { private: double y; double z; public: double x; };
z is not available to code that is written outside the class.
A C++ class is similar to a(n)
structure
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?
#ifndef
When you dereference an object pointer, use the
-> operator
What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) { cout << x << endl; } TestClass () { cout << "Hello!" << endl; } }; int main () { TestClass test; return 0; }
Hello!
The process of object-orientated analysis can be viewed as the following steps:
Identify objects, then define each object's attributes, behaviors, and relationships.
In C++11, you can use __ to initialize a member variable in its declaration statement.
In-place initialization
The constructor function's return type is
None of these
How many default constructors can a class have?
Only one. (Otherwise you'd have a duplicate function, which is not allowed.)
The type of member function that may be called from a statement outside the class is
Public
Assuming that Rectangle is a class name, what can you say is TRUE, given the following statement? Rectangle *BoxPtr;
The statement defines a Rectangle pointer variable named *BoxPtr.
In OOP terminology, an object's member variables are often called it's ___ and its member functions can be referred to as it behaviors or its ___.
attributes, methods
When a constructor has a member initialization list, the initializations take place
before any statements in the body of the constructor execute.
When a member function is defined outside of the class declaration, the function name must be qualified with the
class name, followed by the scope resolution operator
In C++11 you can have one constructor call another constructor in the same class by using
constructor delegation
A ________ is a member function that is automatically called when a class object is ________.
constructor, created
A class is a(n) ________ that is defined by the programmer.
data type
In a procedural program you typically have ________ stored in a collection of variables and a set of ________ that perform operations on the data.
data, functions
Objects are created from abstract data types that encapsulate ________ and ________ together.
data, functions
When a constructor function accepts no arguments, or does NOT have to accept arguments because of default arguments, it is called a(n)
default constructor
The following code shows an example of ________ class Point { private: double y = 5.70; double z = 3.0; public: Public member functions go here... };
in-place initialization
When the body of a member function is defined inside a class declaration, it is said to be
inline
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?
myCar.accelerate();
The destructor function's return type is
nothing; destructors have no return type
If you do NOT declare an access specification, the default for members of a class is
private
Examples of access specifiers are the key words:
private and public
If a local variable and a global variable have the same name within the same program, the ___ resolution operator must be used.
scope