Deck 9: 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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/35
Play
Full screen (f)
Deck 9: Classes
1
A constructor can specify the return type:
A) int.
B) string.
C) void.
D) A constructor cannot specify a return type.
A) int.
B) string.
C) void.
D) A constructor cannot specify a return type.
D
2
Which of the following preprocessor directives does not constitute part of the preprocessor wrapper?
A) #define
B) #endif
C) #ifndef
D) #include
A) #define
B) #endif
C) #ifndef
D) #include
D
3
Member function definitions:
A) Always require the binary scope operator ::).
B) Require the binary scope operator only when being defined outside of the definition of their class.
C) Can use the binary scope operator anywhere, but become public functions.
D) Must use the binary scope operator in their function prototype.
A) Always require the binary scope operator ::).
B) Require the binary scope operator only when being defined outside of the definition of their class.
C) Can use the binary scope operator anywhere, but become public functions.
D) Must use the binary scope operator in their function prototype.
B
4
In the source-code file containing a class's member function definitions, each member function definition must be tied to the class definition by preceding the member function name with the class name and ::, which is known as the:
A) Member definition linker.
B) Class implementation connector.
C) Source code resolver.
D) Binary scope resolution operator.
A) Member definition linker.
B) Class implementation connector.
C) Source code resolver.
D) Binary scope resolution operator.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
5
The compiler will implicitly create a default constructor if:
A) The class does not contain any data members.
B) The programmer specifically requests that the compiler do so.
C) The class does not define any constructors.
D) The class already defines a default constructor.
A) The class does not contain any data members.
B) The programmer specifically requests that the compiler do so.
C) The class does not define any constructors.
D) The class already defines a default constructor.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
6
Variables defined inside a member function of a class have:
A) File scope.
B) Class scope.
C) Block scope.
D) Class or block scope, depending on whether the binary scope resolution operator ::) is used.
A) File scope.
B) Class scope.
C) Block scope.
D) Class or block scope, depending on whether the binary scope resolution operator ::) is used.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
7
Calling a member function of an object requires which item?
A) The dot operator.
B) Open and close braces.
C) The class name.
D) None of the above.
A) The dot operator.
B) Open and close braces.
C) The class name.
D) None of the above.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
8
A header file is typically given the filename extension:
A) .h
B) .hdr
C) .header
D) .cpp
A) .h
B) .hdr
C) .header
D) .cpp
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
9
Classes cannot:
A) Be derived from other classes.
B) Initialize data members in the class definition.
C) Be used to model attributes and behaviors of objects.
D) Include objects from other classes as members.
A) Be derived from other classes.
B) Initialize data members in the class definition.
C) Be used to model attributes and behaviors of objects.
D) Include objects from other classes as members.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
10
When a client code programmer uses a class whose implementation is in a separate file from its interface, that implementation code is merged with the client's code during the:
A) Programming phase.
B) Compiling phase.
C) Linking phase.
D) Executing phase.
A) Programming phase.
B) Compiling phase.
C) Linking phase.
D) Executing phase.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
11
Member access specifiers public and private) can appear:
A) In any order and multiple times.
B) In any order public first or private first) but not multiple times.
C) In any order and multiple times, if they have brackets separating each type.
D) Outside a class definition.
A) In any order and multiple times.
B) In any order public first or private first) but not multiple times.
C) In any order and multiple times, if they have brackets separating each type.
D) Outside a class definition.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
12
Parameterized stream manipulator setfill specifies the fill character that's displayed when an output is displayed in a field wider than the number of characters or digits in the output. The effect of setfill applies:
A) Only to the current value being displayed.
B) Only to outputs displayed in the current statement.
C) Until explicitly set to a different setting.
D) Until the output buffer is flushed.
A) Only to the current value being displayed.
B) Only to outputs displayed in the current statement.
C) Until explicitly set to a different setting.
D) Until the output buffer is flushed.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
13
Assuming that Grades.h is found in the current directory and the iostream header file is found in the C++ Standard Library header file directory, which of the following preprocessor directives will fail to find its desired header file?
A) #include
B) #include "iostream"
C) #include
D) #include "Grades.h"
A) #include
B) #include "iostream"
C) #include
D) #include "Grades.h"
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
14
Attributes of a class are also known as:
A) Constructors.
B) Local variables.
C) Data members.
D) Classes.
A) Constructors.
B) Local variables.
C) Data members.
D) Classes.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
15
When compiling a class's source code file which does not contain a main function), the information in the class's header file is used for all of the following, except:
A) Ensuring that the header of each member function matches its prototype.
B) Ensuring that each member function knows about the class's data members and other member functions.
C) Determining the correct amount of memory to allocate for each object of the class.
D) All of the above are uses that the compiler has for the header file information.
A) Ensuring that the header of each member function matches its prototype.
B) Ensuring that each member function knows about the class's data members and other member functions.
C) Determining the correct amount of memory to allocate for each object of the class.
D) All of the above are uses that the compiler has for the header file information.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
16
A class-scope variable hidden by a block-scope variable can be accessed by preceding the variable name with the class name followed by:
A) ::
B) :
C) .
D) ->
A) ::
B) :
C) .
D) ->
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
17
A default constructor has how many parameters?
A) 0.
B) 1.
C) 2.
D) Variable number.
A) 0.
B) 1.
C) 2.
D) Variable number.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
18
All of the following are true about classes, except:
A)Classes have attributes and behaviors.
B)The first class in any C++ program is main.
C)An object must be created from a class before it can be used.
D)A class's functions hide from the user the complex tasks they perform.
A)Classes have attributes and behaviors.
B)The first class in any C++ program is main.
C)An object must be created from a class before it can be used.
D)A class's functions hide from the user the complex tasks they perform.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
19
In the UML, the top compartment of the rectangle modeling a class contains:
A) The class's name.
B) The class's attributes.
C) The class's behaviors.
D) All of the above.
A) The class's name.
B) The class's attributes.
C) The class's behaviors.
D) All of the above.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
20
Every object of the same class:
A) Gets a copy of every member function and member variable.
B) Gets a copy of every member variable.
C) Gets a copy of every member function.
D) Shares pointers to all member variables and member functions.
A) Gets a copy of every member function and member variable.
B) Gets a copy of every member variable.
C) Gets a copy of every member function.
D) Shares pointers to all member variables and member functions.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
21
What type of member functions allow a client of a class to assign values to private data members?
A) Client member functions.
B) Get member functions.
C) Set member functions.
D) None of the above.
A) Client member functions.
B) Get member functions.
C) Set member functions.
D) None of the above.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
22
If a member function of a class already provides all or part of the functionality required by a constructor or another member function then:
A) Copy and paste that member function's code into this constructor or member function.
B) Call that member function from this constructor or member function.
C) That member function is unnecessary.
D) This constructor or member function is unnecessary.
A) Copy and paste that member function's code into this constructor or member function.
B) Call that member function from this constructor or member function.
C) That member function is unnecessary.
D) This constructor or member function is unnecessary.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
23
A default constructor:
A) Is a constructor that must receive no arguments.
B) Is the constructor generated by the compiler when no constructor is provided by the programmer.
C) Does not perform any initialization.
D) Both a) and b).
A) Is a constructor that must receive no arguments.
B) Is the constructor generated by the compiler when no constructor is provided by the programmer.
C) Does not perform any initialization.
D) Both a) and b).
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
24
The type of function a client would use to check the balance of a bank account would be:
A) A utility function.
B) A predicate function.
C) An access function.
D) A constructor.
A) A utility function.
B) A predicate function.
C) An access function.
D) A constructor.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
25
Utility functions:
A) Are private member functions that support operations of the class's other member functions.
B) Are part of a class's interface.
C) Are intended to be used by clients of a class.
D) Are a type of constructor.
A) Are private member functions that support operations of the class's other member functions.
B) Are part of a class's interface.
C) Are intended to be used by clients of a class.
D) Are a type of constructor.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
26
Given the class definition:
Class CreateDestroy
{
Public:
CreateDestroy) { cout << "constructor called, "; }
~CreateDestroy) { cout << "destructor called, "; }
};
What will the following program output?
Int main)
{
For int i = 1; i <= 2; i++ )
CreateDestroy cd;
Return 0;
}
A) constructor called, destructor called, constructor called, destructor called,
B) constructor called, constructor called,
C) constructor called, constructor called, destructor called, destructor called,
D) Nothing.
Class CreateDestroy
{
Public:
CreateDestroy) { cout << "constructor called, "; }
~CreateDestroy) { cout << "destructor called, "; }
};
What will the following program output?
Int main)
{
For int i = 1; i <= 2; i++ )
CreateDestroy cd;
Return 0;
}
A) constructor called, destructor called, constructor called, destructor called,
B) constructor called, constructor called,
C) constructor called, constructor called, destructor called, destructor called,
D) Nothing.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following statements is false?
A) Always try to localize the effects of changes to a class' data members by accessing and manipulating the data members through their set and get functions.
B) Services useful to the client should typically be provided in the class' private interface. Change is the rule rather than the exception. You should anticipate that your code will be modified.
C) Providing public set and get functions does allow clients of the class to access hidden data, but only indirectly.
A) Always try to localize the effects of changes to a class' data members by accessing and manipulating the data members through their set and get functions.
B) Services useful to the client should typically be provided in the class' private interface. Change is the rule rather than the exception. You should anticipate that your code will be modified.
C) Providing public set and get functions does allow clients of the class to access hidden data, but only indirectly.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following statements is not true of a constructor and destructor of the same class?
A) They both have the same name aside from the tilde ~) character.
B) They are both usually called once per object created.
C) They both are able to have default arguments.
D) Both are called automatically, even if they are not explicitly defined in the class.
A) They both have the same name aside from the tilde ~) character.
B) They are both usually called once per object created.
C) They both are able to have default arguments.
D) Both are called automatically, even if they are not explicitly defined in the class.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
29
When independent software vendors provide class libraries to clients, they typically give the __________ for the class's interface and the __________ for the class's implementation.
A) Source code file, source code file.
B) Source code file, object file.
C) Object file, source code file.
D) Object file, object file.
A) Source code file, source code file.
B) Source code file, object file.
C) Object file, source code file.
D) Object file, object file.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
30
A client changing the values of private data members is:
A) Only possible by calling private member functions.
B) Possible using public functions and references.
C) Never possible.
D) Only possible if the private variables are not declared inside the class.
A) Only possible by calling private member functions.
B) Possible using public functions and references.
C) Never possible.
D) Only possible if the private variables are not declared inside the class.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
31
Returning references to non-const, private data:
A) Allows private functions to be modified.
B) Is only dangerous if the binary scope resolution operator ::) is used in the function prototype.
C) Allows private member variables to be modified, thus "breaking encapsulation."
D) Results in a compiler error.
A) Allows private functions to be modified.
B) Is only dangerous if the binary scope resolution operator ::) is used in the function prototype.
C) Allows private member variables to be modified, thus "breaking encapsulation."
D) Results in a compiler error.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following statements is not true of a destructor?
a. It performs termination housekeeping.
b. It's called before the system reclaims the object's memory.
c. If the programmer does not explicitly provide a destructor, the compiler creates an "empty" destructor.
d. It releases the object's memory.
a. It performs termination housekeeping.
b. It's called before the system reclaims the object's memory.
c. If the programmer does not explicitly provide a destructor, the compiler creates an "empty" destructor.
d. It releases the object's memory.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
33
The assignment operator =) can be used to:
A) Test for equality.
B) Copy data from one object to another.
C) Compare two objects.
D) Copy a class' member functions.
A) Test for equality.
B) Copy data from one object to another.
C) Compare two objects.
D) Copy a class' member functions.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
34
Given the class definition:
Class CreateDestroy
{
Public:
CreateDestroy) { cout << "constructor called, "; }
~CreateDestroy) { cout << "destructor called, "; }
};
What will the following program output?
Int main)
{
CreateDestroy c1;
CreateDestroy c2;
Return 0;
}
A) constructor called, destructor called, constructor called, destructor called,
B) constructor called, destructor called,
C) constructor called, constructor called,
D) constructor called, constructor called, destructor called, destructor called,
Class CreateDestroy
{
Public:
CreateDestroy) { cout << "constructor called, "; }
~CreateDestroy) { cout << "destructor called, "; }
};
What will the following program output?
Int main)
{
CreateDestroy c1;
CreateDestroy c2;
Return 0;
}
A) constructor called, destructor called, constructor called, destructor called,
B) constructor called, destructor called,
C) constructor called, constructor called,
D) constructor called, constructor called, destructor called, destructor called,
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following statements about separating a class's interface and implementation is not true?
A) Inline member function definitions are included in the header file.
B) Changes in the class's interface will affect the client.
C) Private data members are included in the header file.
D) Changes in the class's implementation will affect the client.
A) Inline member function definitions are included in the header file.
B) Changes in the class's interface will affect the client.
C) Private data members are included in the header file.
D) Changes in the class's implementation will affect the client.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck