Which of the following can be used to create an abstract class in the C++…

2023

Which of the following can be used to create an abstract class in the C++ programming language?

  1. A.

    By using the pure virtual function in the class

  2. B.

    By declaring a virtual function in the base class

  3. C.

    By declaring the virtual keyword afterward the class declaration

  4. D.

    More than one of the above

  5. E.

    None of the above

Attempted by 152 students.

Show answer & explanation

Correct answer: A

To create an abstract class in C++, a class must contain at least one pure virtual function. A pure virtual function is declared by using the syntax = 0 in the function declaration, for example: virtual void func() = 0;. This makes the class abstract, meaning it cannot be instantiated directly. Any derived class must provide an implementation for all pure virtual functions to be instantiable. Now, let's evaluate the options: Option A: Using a pure virtual function in the class — This is correct because it directly creates an abstract class. Option B: Declaring a virtual function in the base class — This is incorrect because a regular virtual function does not make the class abstract; it only enables runtime polymorphism. Option C: Declaring the virtual keyword after the class declaration — This is incorrect because there is no such syntax in C++ to declare 'virtual' after the class name. Option D: More than one of the above — This is incorrect because only Option A is correct. Option E: None of the above — This is incorrect because Option A is correct. Therefore, the correct answer is Option A.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs