Skip to main content

Polymorphism

1).What is polymorphism in C++?

1) Ability to process objects differently based on their type
2) Inheritance of base class properties
3) A type of memory management
4) None of the above

2).What are the two types of polymorphism in C++?

1) Static and Dynamic
2) Compile-time and Runtime
3) Both A and B
4) None of the above

3).Which function is used to achieve runtime polymorphism?

1) Virtual function
2) Static function
3) Inline function
4) None of the above

4).What is required to make a function in a base class virtual?

1) Use the virtual keyword
2) Use the static keyword
3) Declare the function as private
4) None of the above

5).How does C++ implement runtime polymorphism?

1) By using vtables and vptr
2) Through function overloading
3) Using templates
4) None of the above

6).What is function overloading?

1) Same function name with different parameters
2) Multiple classes sharing the same function
3) A function calling itself
4) None of the above

7).Can constructors be virtual in C++?

1) No
2) Yes
3) Only for abstract classes
4) None of the above

8).What is the difference between function overloading and overriding?

1) Overloading happens in the same class; overriding happens in inherited classes
2) Overriding requires virtual functions
3) Both A and B
4) None of the above

9).What is the purpose of the 'override' specifier in C++?

1) Ensures a function is overriding a base class function
2) Marks a function as virtual
3) Declares a function as static
4) None of the above

10).Can a virtual function in the base class be overridden in the derived class?

1) Yes
2) No
3) Only if declared with final
4) None of the above