How many instances (objects) of an abstract class can be directly created in C++? Choose the correct count.

Difficulty: Easy

Correct Answer: 0

Explanation:


Introduction:
Abstract classes define interfaces with one or more pure virtual functions. They are intended only as base types. This question checks whether you recall the fundamental restriction on constructing abstract types in C++.


Given Data / Assumptions:

  • A class has at least one pure virtual function (written with = 0).
  • No concrete override is provided in that class.
  • We are asking about direct instantiation of that abstract class.


Concept / Approach:
By definition, abstract classes cannot be instantiated. Only concrete classes (those without unimplemented pure virtuals) can have objects created. Abstract bases are used through pointers/references to enable runtime polymorphism and interface-based design.


Step-by-Step Solution:
1) Declare a base with a pure virtual function.2) Attempt to write Base b; and observe a compile-time error citing abstract type.3) Derive a class that implements all pure virtuals; instantiate the derived type instead.4) Use a Base* pointing to Derived objects for polymorphic behavior.


Verification / Alternative check:
Compilers explicitly diagnose attempts to instantiate abstract classes. This is testable with a minimal program.


Why Other Options Are Wrong:
1, 5, 13: any positive number is impossible; the correct count is zero.


Common Pitfalls:
Forgetting that a pure virtual destructor still needs a definition; also believing that abstract classes cannot have constructors—constructors of abstract bases do run during derived construction.


Final Answer:
0

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion