QUESTION 1 If Americans are objects of the same class, which of the following at
ID: 3830765 • Letter: Q
Question
QUESTION 1
If Americans are objects of the same class, which of the following attributes would most likely be represented by a static variable of that class?
Age.
The President.
Place of Birth.
Favorite Food.
QUESTION 2
An error occurs if:
A non-reference, non-const, primitive data member is initialized in the member initialization list.
An object data member is not initialized in the member initialization list.
An object data member does not have a default constructor.
An object data member is not initialized in the member initialization list and does not have a default constructor.
QUESTION 3
A class-scope variable hidden by a block-scope variable can be accessed by preceding the variable name with the class name followed by:
::
:
.
->
QUESTION 4
A class s functions can throw exceptions, such as __________to indicate invalid data.
invalid_data
bad_data
invalid_argument
bad_argument
QUESTION 5
Which of the following statements will not produce a syntax error?
Defining a const member function that modifies a data member of the object.
Invoking a non-const member function on a const object.
Declaring an object to be const.
Declaring a constructor to be const.
QUESTION 6
A client changing the values of private data members is:
Only possible by calling private member functions.
Possible using public functions and references.
Never possible.
Only possible if the private variables are not declared inside the class.
QUESTION 7
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;
}
constructor called, destructor called, constructor called, destructor called,
constructor called, constructor called,
constructor called, constructor called, destructor called, destructor called,
Nothing
QUESTION 8
Member function definitions:
Always require the scope resolution operator (::).
Require the scope resolution operator only when being defined outside of the definition of their class.
Can use the scope resolution operator anywhere, but become public functions.
Must use the scope resolution operator in their function prototype.
QUESTION 9
Variables defined inside a member function of a class have:
File scope.
Class scope.
Block scope.
Class or block scope, depending on whether the binary scope resolution operator (::) is used.
QUESTION 10
If a member function of a class already provides all or part of the functionality required by a constructor or another member function then:
Copy and paste that member function s code into this constructor or member function.
Call that member function from this constructor or member function.
That member function is unnecessary.
This constructor or member function is unnecessary.
QUESTION 11
Member access specifiers (public and private) can appear:
In any order and multiple times.
In any order (public first or private first) but not multiple times.
In any order and multiple times, if they have brackets separating each type.
Outside a class definition.
QUESTION 12
Static member functions:
Can use the this pointer.
Can access only other static member functions and static data members.
Cannot be called until an object of their class is instantiated.
Can be declared const as well.
3.125 points
QUESTION 13
The assignment operator (=) can be used to:
Test for equality.
Copy data from one object to another.
Compare two objects.
Copy a class.
3.125 points
QUESTION 14
Every object of the same class:
Gets a copy of every member function and member variable.
Gets a copy of every member variable.
Gets a copy of every member function.
Shares pointers to all member variables and member functions.
3.125 points
QUESTION 15
A default constructor:
Is a constructor that must receive no arguments.
Is the constructor generated by the compiler when no constructor is provided by the programmer.
Does not perform any initialization.
Both (a) and (b).
3.125 points
QUESTION 16
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;
}
constructor called, destructor called, constructor called, destructor called,
constructor called, destructor called,
constructor called, constructor called
constructor called, constructor called, destructor called, destructor called,
A.Age.
B.The President.
C.Place of Birth.
D.Favorite Food.
Explanation / Answer
Answer in Bold/
QUESTION 1
If Americans are objects of the same class, which of the following attributes would most likely be represented by a static variable of that class?
B. The President as this is the only value which will remaiun common among all.
QUESTION 2
An error occurs if:
An object data member is not initialized in the member initialization list and does not have a default constructor.
QUESTION 3
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. ::
Question 4:
A class s functions can throw exceptions, such as __________to indicate invalid data.
A. invalid_data
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.