What is the purpose of the override specifier in C++?
class Derived : public Base
{
public:
void show() override;
};
Options
-
A.
It tells the compiler that the function is intended to override a virtual function from the base class.
-
B.
It makes the function automatically static.
-
C.
It prevents the function from being called.
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
A.
It tells the compiler that the function is intended to override a virtual function from the base class.
Detailed Explanation
Answer: (A) It tells the compiler that the function is intended to override a virtual function from the base class.
The override specifier is used in a derived class to indicate that a member function is intended to override a virtual function from its base class.
It also helps the compiler detect mistakes, such as an incorrect function signature where the programmer expected an override.
It does not make the function static and does not prevent the function from being called.