C++ MCQs - Abstract Classes
This section focuses on the "Abstract Classes" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. A class is made abstract by declaring at least one of its functions as?
A. impure virtual function
B. pure virtual function
C. pure abstract function
D. impure abstract function
View Answer
Ans : B
Explanation: A class is made abstract by declaring at least one of its functions as pure virtual function
2. A pure virtual function is specified by placing?
A. -1
B. 0
C. 1
D. infinite
View Answer
Ans : B
Explanation: A pure virtual function is specified by placing "= 0" in its declaration
3. Classes that can be used to instantiate objects are called?
A. concrete classes
B. interface
C. abstract class
D. None of the above
View Answer
Ans : A
Explanation: Classes that can be used to instantiate objects are called concrete classes.
4. Which of the following is true?
A. The C++ interfaces are implemented using abstract classes
B. The purpose of an abstract class is to provide an appropriate base class from which other classes can inherit.
C. Abstract classes cannot be used to instantiate objects and serves only as an interface.
D. All of the above
View Answer
Ans : D
Explanation: All of the above statement is true.
5. Where does the abstract class is used?
A. base class only
B. derived class
C. both derived & base class
D. virtual class
View Answer
Ans : A
Explanation: As base class only as it helps in encapsulation of similar functioning of derived classes.
6. Which class is used to design the base class?
A. abstract class
B. derived class
C. base class
D. derived & base class
View Answer
Ans : A
Explanation: Abstract class is used to design base class because functions of abstract class can be overridden in derived class hence derived class from same base class can have common method with different implementation, hence forcing encapsulation.
7. We cannot make an instance of an abstract base class
A. TRUE
B. FALSE
C. Can be true and false
D. Can not say
View Answer
Ans : A
Explanation: The above statement is true
8. We can make an instance of an abstract super class
A. TRUE
B. FALSE
C. Can be true and false
D. Can not say
View Answer
Ans : B
Explanation: The above statement is false
9. Which is the correct syntax of defining a pure virtual function?
A. pure virtual return_type func();
B. virtual return_type func() pure;
C. virtual return_type func() = 0;
D. virtual return_type func();
View Answer
Ans : C
Explanation: virtual return_type function_name(parameters) = 0; where {=0} is called pure specifier.
10. Which is the correct statement about pure virtual functions?
A. They should be defined inside a base class
B. Pure keyword should be used to declare a pure virtual function
C. Pure virtual function is implemented in derived classes
D. Pure virtual function cannot implemented in derived classes
View Answer
Ans : C
Explanation: Pure virtual function cannot implemented in derived classes
Discussion