Programming MCQs

MCQ On Polymorphism, Pointer & Virtual Function In C++

Pinterest LinkedIn Tumblr

This set of MCQ on polymorphism, pointer & virtual function in C++ includes collections of top 20 multiple-choices questions on run time polymorphism, compile-time polymorphism, pointers, and their types, void pointers, null pointers, object pointer, this pointer along with pointer expressions and pointer arithmetic. It also includes virtual functions, pure virtual functions with their properties. 

1. In compile-time polymorphism, a compiler is able to select the appropriate function for a particular call at the compile time itself, which is known as …………
A) early binding
B) static binding
C) static linking
D) All of the above

2. ……………. binding means that an object is bound to its function call at compile time.
A) late
B) static
C) dynamic
D) fixed

3. C++ supports run time polymorphism with the help of virtual functions, which is called …………….. binding.
A) dynamic
B) run time
C) early binding
D)static

4. State whether the following statements about pointers in C++ are True.
i) A pointer can be incremented (++) or decremented (–)
ii) Any integer can be added to or subtracted from a pointer
iii) One pointer can be subtracted from another
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii

5. ………………. are also known as generic pointers, which refer to variables of any type.
A) void pointers
B) null pointers
C) this pointer
D) base pointer

6. The pointers which are not initialized in a program are called ……………..
A) void pointers
B) null pointers
C) this pointer
D) base pointer

7. …………………… is useful in creating objects at run time.
A) void pointer
B) null pointer
C) this pointer
D) object pointer

8. A …………………. refers to an object that that currently invokes a member function.
A) void pointers
B) null pointers
C) this pointer
D) base pointer

9. The …………………. cannot be directly used to access all the members of the derived class.
A) void pointers
B) null pointers
C) this pointer
D) base pointer

10. Run time polymorphism is achieved only when a ……………….. is accessed through a pointer to the base class.
A) member function
B) virtual function
C) static function
D) real function

Read Also: Multiple Choice Questions On C++ Operator Overloading

11. If a ……………………… is defined in the base class, it need not be necessarily redefined in the derived class.
A) member function
B) virtual function
C) static function
D) real function

12. …………………………. is a function declared in a base class that has no definition relative to the base class.
A) member function
B) virtual function
C) pure virtual function
D) pure function

13. State whether the following statements about virtual functions are True or False.
i) A virtual function, equated to zero is called pure virtual function.
ii) A class containing pure virtual function is called an abstract class
A) True, True
B) True, False
C) False, True
D) False, False

14. The main objective of an abstract base class is to provide some traits to the derived class and to create a ………………………. required for achieving run time polymorphism.
A) void pointers
B) null pointers
C) this pointer
D) base pointer

15. State, whether the following statements about virtual functions are True.
i) The virtual function must be a member of some class
ii) virtual functions cannot be static members
iii) A virtual function can not be a friend of another class.
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii

16. The important application of ………………… is to return the object it points to.
A) void pointers
B) null pointers
C) this pointer
D) base pointer

17. The pointer to a function is known as …………………. function.
A) forward
B) pointer
C) callback
D) backward

18. We can manipulate a pointer with the indirection operator (*), which is also known as ……………………
A) reference operator
B) dereference operator
C) direction operator
D) indirection operator

19. Using the ………………………., we can change the contents of the memory location.
A) reference operator
B) dereference operator
C) direction operator
D) indirection operator

20. If we attempt to dereference an uninitialized pointer, it will ………………….. by referring to any other location in memory.
A) cause a compile-time error
B) run time error
C) cause run time error
D) executes

Answers

1. D) All of the above
2. B) static
3. A) dynamic
4. D) All i, ii and iii
5. A) void pointers
6. B) null pointers
7. D) object pointer
8. C) this pointer
9. D) base pointer
10. B) virtual function
11. B) virtual function
12. C) pure virtual function
13. A) True, True
14. D) base pointer
15. A) i and ii only
16. C) this pointer
17. C) callback
18. B) dereference operator
19. B) dereference operator
20. C) cause run time error

Read Next: Top 20 MCQ Questions On Inheritance In C++
Read More: C and C++ MCQ Questions

Author

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Comments are closed.