Classes & Objects MCQ Questions
21. Constructor is executed when _____.
A. An object goes out of scope.
B. A class is declared
C. An object is created
D. An object is used
View Answer
Ans : C
Explanation: Constructor is executed when An object is created.
22. How many ways of reusing are there in class hierarchy?
A. 1
B. 3
C. 4
D. 2
View Answer
Ans : D
Explanation: Class hierarchies promote reuse in two ways. They are code sharing and interface sharing.
23. Where does the object is created?
A. Class
B. Constructor
C. Destructors
D. Attributes
View Answer
Ans : A
Explanation: In class, only all the listed items except class will be declared.
24. Which of the following is a valid class declaration?
A. Class A { int x; };
B. Class B { }
C. Public class A { }
D. Object A { int x; };
View Answer
Ans : A
Explanation: Class A { int x; }; is a valid class declaration.
25. Which of the following is not correct (in C++) ?i) Class templates and function templates are instantiated in the same way
ii) Class templates differ from function templates in the way they are initiated
iii) Class template is initiated by defining an object using the template argument
iv) Class templates are generally used for storage classes.
A. i
B. i & ii
C. ii ,iii, iv
D. iv
View Answer
Ans : C
Explanation: In C++ class template and function template are similar in the way the are initiated. Class template are not used for storage class. Class templates and function templates are instantiated in the same way and Class template is not initiated by defining an object using the template. So (2), (3), (4) are not correct in C++.
26. Which of the following keywords is used to control access to a class member?
A. Default
B. Break
C. Protected
D. Asm
View Answer
Ans : C
Explanation: Protected keywords is used to control access to a class member
27. Which of the following statements is incorrect?
A. Destructor of base class should always be static
B. Destructor of base class should always be virtual.
C. Destructor of base class should not be virtual.
D. Destructor of base class should always be private.
View Answer
Ans : B
Explanation: Destructor of base class should always be virtual statements is incorrect
28. Which operator can not be overloaded?
A. +
B. ::
C. -
D. *
View Answer
Ans : B
Explanation: :: operator can not be overloaded
29. When Virtual Table is created?
A. Every Class has VTable
B. Class inherited from other Class
C. Class has atleast one Virtual Function
D. When a Class Overrides the function of Base class
View Answer
Ans : C
Explanation: When Virtual Table is created Class has atleast one Virtual Function
30. What is the size of empty class?
A. 0
B. 2
C. 4
D. 1
View Answer
Ans : D
Explanation: When we create object of empty class at that time State of that object is nothing. Behaviour of that object is also nothing, but compiler assigns a unique address to that object. Memory in Computer is always organized in the form of bytes and minimum memory available at object address location is 1 byte. That's why size of object of empty class is 1 byte.
Also check :
Discussion