C++ MCQs - Virtual Functions

This section focuses on the "Virtual Functions" 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 ___________ is a member function which is declared within a base class and is re-defined (overridden) by a derived class.

A. Static function
B. Virtual function
C. Lambdas function
D. Dynamic function

View Answer


2. Functions are declared with a _________ keyword in base class.

A. init
B. self
C. virtual
D. extend

View Answer


3. Virtual functions cannot be static.

A. TRUE
B. FALSE
C. Can be true or false
D. Can not say

View Answer


4. Which of the following are the limitations of virtual functions?

A. function call takes slightly longer time
B. virtual functions can make it a little more difficult to figure out where a function is being called from
C. Both A and B
D. None of the above

View Answer


5. Virtual functions are accessed through?

A. variable
B. array
C. object
D. object pointers

View Answer


6. When the function has no definition, such function is known as ________ function.

A. pure virtual function
B. do-nothing
C. late function
D. Both A and B

View Answer


7. What is the syntax for overriding a virtual function in a derived class?

A. virtual void functionName() const;
B. void functionName() override;
C. virtual void functionName() = 0;
D. void functionName() const override;

View Answer


8. Which class cannot have virtual functions?

A. Derived classes
B. Abstract classes
C. Concrete classes
D. None of the above

View Answer


9. Which access specifier can a virtual function have in a base class?

A. Private
B. Protected
C. Public
D. Any of the above

View Answer


10.  A virtual function can be a friend function of another class.

A. Yes
B. No
C. Can be yes or no
D. Can not say

View Answer





Discussion



* You must be logged in to add comment.