Which statement about a pure virtual function in C++ is correct?

class Base
{
public:
    virtual void show() = 0;
};
                        

Options

  • A. A pure virtual function can never have any definition anywhere.
  • B. A pure virtual function may have a definition, but the class containing it is still abstract.
  • C. A pure virtual function must always be static.
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. A pure virtual function may have a definition, but the class containing it is still abstract.

Detailed Explanation

Answer: (B) A pure virtual function may have a definition, but the class containing it is still abstract.

A pure virtual function is normally declared using = 0.

It is possible in C++ to provide a separate definition for a pure virtual function in certain situations. However, the class still remains abstract because the function is declared pure virtual.

The important point for an exam is that = 0 makes the function pure virtual; it does not simply mean that no definition can ever exist.