1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. Why is the override specifier preferred on a derived…

Added 30 Nov -0001

Why is the override specifier preferred on a derived virtual function?

  1. It turns a would-be silent non-override, such as a missing const or a wrong parameter type, into a compile error Correct answer
  2. It allows the function to be inlined by the compiler, because the exact target is known at compile time
  3. It forces the base function to become virtual for the first time, even when the base declares it non-virtual
  4. It makes the function callable through a base pointer, which is otherwise impossible for a derived member function

Correct answer

A. It turns a would-be silent non-override, such as a missing const or a wrong parameter type, into a compile error

14 views

MCQSEXAM

Explanation

override is a compile-time assertion that the function really overrides a base virtual, so a signature mismatch that would otherwise create a new overload and break polymorphism becomes a hard error. It is often combined with final, which blocks further overriding in deeper classes. It neither creates virtuality, which comes from the base declaration, nor affects inlining.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? 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