1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. What makes a class abstract in C++?

Added 30 Nov -0001

What makes a class abstract in C++?

  1. Declaring at least one pure virtual function, such as virtual void f() = 0; Correct answer
  2. Declaring the constructor protected, so only derived classes can create objects
  3. Making every member function virtual, so the class cannot be instantiated on its own
  4. Declaring all data members private, so no outside code can construct it

Correct answer

A. Declaring at least one pure virtual function, such as virtual void f() = 0;

14 views

MCQSEXAM

Explanation

Abstract class cannot be instantiated because it has at least one pure virtual function, whether declared in it or inherited unimplemented. It may still define constructors and non-pure members, which derived classes use. A protected constructor by itself only blocks direct construction from outside and does not make the class abstract.

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