Which design decision best demonstrates abstraction in a C++ class?
09 Introduction to Object-Oriented Programming Online Quiz Questions
Use this free practice quiz with 20 questions to review 09 Introduction to Object-Oriented Programming, test your knowledge, and prepare for your next test or exam.
A Car needs to start an Engine but is not a specialized kind of Engine. Which design most directly models this relationship?
- A
Make Car publicly inherit from Engine.
- B
Copy the implementation of Engine into Car.
- C
Store an Engine object as a member of Car.
- D
Make Engine a friend of Car without storing one.
Which design best expresses a genuine substitutable relationship between Circle and Shape?
- A
A Circle publicly inherits from Shape and implements the Shape interface.
- B
A Circle privately stores a Shape solely to reuse its data layout.
- C
A Circle exposes all of Shape's private members directly.
- D
A Circle duplicates Shape's functions without any relationship between the types.
Which two features are appropriate for a C++ base class intended to serve as a polymorphic interface? Select all correct choices.
- A
A public pure virtual function such as area() = 0
- B
A nonvirtual data member containing a concrete shape
- C
A virtual destructor
- D
A private constructor that prevents every derived class from constructing objects
Which two statements correctly describe the benefits of runtime polymorphism in the Shape and print_area example? Select all correct choices.
- A
The caller must know the concrete class before calling area.
- B
The caller can use a Shape reference while the concrete override is selected at runtime.
- C
The base class must contain the complete implementation of every shape's area.
- D
A new derived shape can work with the existing function if it implements the required interface.
In C++, members of a class are public by default.
- A
True
- B
False
Passing a polymorphic derived object by value as a base object can cause object slicing.
- A
True
- B
False
What C++ keyword can be placed after Circle::area to ask the compiler to verify that it overrides a virtual function from Shape?
Which C++ access specifier should be used for a balance data member that is an implementation detail and should be accessible only to the class and permitted friends, not to derived classes or general outside code?
A relationship in which one object contains another object as a member is commonly called a relationship.
In the declaration virtual double area() const ;, what notation marks area as a pure virtual function?
A team is deciding whether a new class should contain an existing helper object or publicly inherit from it. Explain when composition is the better choice and when public inheritance is justified. Include one example of each and explain the design relationship each choice communicates.
In the Document example, which interface design best lets clients save a document without depending on validation or storage details?
- A
Expose validate and write_to_disk so callers can control the storage sequence.
- B
Expose save while keeping validate and write_to_disk private.
- C
Make every helper protected so all unrelated callers can use it.
- D
Replace save with direct access to the document's storage representation.
What is the most accurate description of the role of protected members in a C++ class hierarchy?
- A
Protected members are intended for the class and its derived classes.
- B
Protected members are accessible only to unrelated callers.
- C
Protected members are always more encapsulated than private members.
- D
Protected members automatically become public in every derived class.
In the C++ example, what is the relationship between BankAccount and account?
- A
BankAccount is an object, and account is a class.
- B
BankAccount is a class, and account is an object.
- C
Both BankAccount and account are objects.
- D
Both BankAccount and account are classes.
Which design choice most directly demonstrates abstraction in the BankAccount example?
- A
Making every data member public so callers can inspect it.
- B
Combining several unrelated classes into one larger class.
- C
Exposing essential operations while hiding unnecessary implementation details.
- D
Replacing all member functions with global functions.
In the given C++ design, why is Car an example of composition?
- A
Car contains an Engine object as a member.
- B
Car publicly inherits from Engine.
- C
Engine is a derived class of Car.
- D
Car and Engine are unrelated because start is called indirectly.
True or false: Because Shape declares area() as a pure virtual function, client code cannot create a Shape object directly.
- A
True
- B
False
What C++ mechanism causes print_area(circle) to call Circle::area() when print_area receives a Shape reference?
What is the standard C++ term for the loss of a derived object's part when it is copied into a base object by value?