Which of the following best represents an abstract data type (ADT) in C++? Choose the option that encapsulates data and behavior behind an interface.

Difficulty: Easy

Correct Answer: Class

Explanation:


Introduction:
An abstract data type is defined by its interface and observable behavior rather than its implementation details. This question asks which choice best captures that idea within C++ terminology.


Given Data / Assumptions:

  • An ADT exposes operations while hiding representation.
  • We distinguish primitive types from user-defined abstractions.
  • Language: C++.


Concept / Approach:
A class is the canonical vehicle for ADTs in C++. It packages data and functions, controls access via public/protected/private, and allows clients to depend on a stable interface while the implementation can change. Primitive types like int and double are concrete machine-level types, not ADTs. The identifier string typically refers to std::string, which is a class implementing an ADT, but the general answer that represents the concept itself is “Class.”


Step-by-Step Solution:
1) Identify ADT properties: interface-first, hidden representation.2) Map these to C++ constructs: classes provide exactly this encapsulation.3) Recognize primitives as non-ADT concrete types.4) Select “Class” as the best conceptual match.


Verification / Alternative check:
Consider a Stack class: push/pop/top define behavior; internal container choice (vector/list) can change without affecting users—hallmark of an ADT.


Why Other Options Are Wrong:
int / double: primitive numeric types, not interface-defined abstractions.string: specific library class; while it is an ADT instance, the general concept is better represented by “Class”.


Common Pitfalls:
Equating ADT solely with inheritance; ADTs can exist without inheritance so long as the interface abstracts representation.


Final Answer:
Class

Discussion & Comments

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