arrow
arrow
arrow
Which of the following C++ statements correctly declares an abstract class?
Question



Which of the following C++ statements correctly declares an abstract class?

A.

class A {virtual void show() = 0;};

B.

class A {void show() = 0;};

C.

class A {void show() { };};

D.

class A {show() = 0;};

Correct option is A

In C++, an abstract class is one that contains at least one pure virtual function. A pure virtual function is defined by assigning 0 to it in the function declaration. The correct way to declare an abstract class with a pure virtual function is:
class A {virtual void show() = 0; };
This syntax tells the compiler that “show” is a pure virtual function, making ‘A’ an abstract class that cannot be instantiated directly.
Information Booster:
1. Abstract Class: An abstract class is a class that cannot be instantiated on its own. It requires at least one pure virtual function.
2. Pure Virtual Function: A function declared by assigning 0 to the virtual function in a class, forcing derived classes to override it.
Additional Knowledge:
· Option (b): Incorrect, as void show() = 0; lacks the virtual keyword.
· Option (c): Incorrect, as it defines a concrete function { }; instead of a pure virtual function.
· Option (d): Incorrect syntax as it lacks both virtual and a function body or assignment.

Free Tests

Free
Must Attempt

Basics of Education: Pedagogy, Andragogy, and Hutagogy

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon12 Mins
languageIcon English
Free
Must Attempt

UGC NET Paper 1 Mock Test 1

languageIcon English
  • pdpQsnIcon50 Questions
  • pdpsheetsIcon100 Marks
  • timerIcon60 Mins
languageIcon English
Free
Must Attempt

Basics of Education: Pedagogy, Andragogy, and Hutagogy

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon12 Mins
languageIcon English
test-prime-package

Access ‘UGC NET Computer Science’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
353k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow