1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. What is the purpose of declaring a member function virtual…

Added 30 Nov -0001

What is the purpose of declaring a member function virtual in C++?

  1. To stop derived classes from redefining it
  2. To force the function to be inlined everywhere
  3. To hide the function from other translation units
  4. To allow dispatch at runtime through a base pointer Correct answer

Correct answer

D. To allow dispatch at runtime through a base pointer

14 views

MCQSEXAM

Explanation

A virtual function is selected at run time from the dynamic type of the object, which enables polymorphism.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs