QUESTION 1 Which of the following is correct? A class can have only one default
ID: 3866887 • Letter: Q
Question
QUESTION 1
Which of the following is correct?
A class can have only one default constructor
A constructor must be declared with a return type
A constructor must be declared for each class
A class can have only one constructor
10 points
QUESTION 2
Which statement is incorrect?
Inline functions are always more efficient than noninline functions
If we use an out of range index with a vector, there will NOT be an error message from the compiler.
A static variable of a class can be changed.
If we use an out of range index with an array, there will NOT be an error message from the compiler.
10 points
QUESTION 3
Which of the following is NOT an accurate comparison between call-by-value and const call-by-reference?
Call by value uses more meory than const call-by-reference in making the copy
Both protect against changing the caller's arguments
Both are very fast for all sizes of objects
Call-by-value copes the argument whereas const call-by-reference does not
10 points
QUESTION 4
A class member that is to be shared among all objects of a class is called
A reference member
A const member
A value member
A static member
10 points
QUESTION 5
Which statement is incorrect?
The keyword static is used in a static function declaration in a class but not in the function definition
A class may not have another class type object as a member.
The functions or data members declared in the private: section of a class can be accessed only in the definition of those functions declared in that class
Any use of the keyword const is a promise to the compiler, and a request to the compiler to enforce the promise
10 points
QUESTION 6
Given the class definition,
class A{
public:
A(){}
A(int x, char y):xx(x), yy(y) {}
// other members
private:
int xx;
char yy;
};
Which definition below is NOT legal?
A x(1);
A x = A(2, 'A');
A x;
A x(2, 'A');
10 points
QUESTION 7
Which statement regarding constructors is incorrect?
A constructor is always named the same as the class. If the class is Foo, then the constructor name is Foo.
A constructor is like a function. It can return any type value needed.
A constructor is a special kind of member function. It is automatically called when an object of that class is declared.
A constructor usually terminates by falling off the end of its block, but a return statement is permitted if there is no argument add following the word return..
10 points
QUESTION 8
Which of the following is NOT a legal access to the class or struct members? Assume each is outside of the class member definitions,
struct S class C class D
{ { {
int x; int x; public:
int y; int y; int x;
} private: int y;
S s; int z; private:
}; int z;
C c; };
D d;
s.x
c.x
d.x
d.y
10 points
QUESTION 9
A base/member initialization list is preceded by
a semicolon
two colons
a dot (or period)
a single colon
10 points
QUESTION 10
A derived class object inherits all the members of the base class. Which of these remarks about the inherited member variables is incorrect?
Inherited members’ memory allocation must be done by the base class constructor for the base class, which must be called.
The base class constructor is the most convenient place to initialize these inherited variables.
Inherited members are need to be allocated memory and should be initialized at creation of a derived class object.
Inherited members are not accessible to the derived class functions so can safely be ignored
A class can have only one default constructor
A constructor must be declared with a return type
A constructor must be declared for each class
A class can have only one constructor
Explanation / Answer
Only answers for each question is given below :
(Since options are not provided in the qustion by a number, I have to write the complete
sentence in the answer)
Question 1:
A class can have only one default constructor
Question 2:
If we use an out of range index with an array, there will NOT be an error message
from the compiler.
Question 3:
Both are very fast for all sizes of objects
Explanation : for smaller objects line int copy by value is fast, for big ones call-by-
reference is faster
Question 4:
A static member
Question 5:
"A class may not have another class type object as a member" is oncorrect
Question 7:
A constructor is like a function. It can return any type value needed.
Explanation : A cnstructor can not return anything.
Queestion 8:
s.x is not a legal access
struct members are accessed using ::
Question 9:
a single column
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.