Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

Which design decision best demonstrates abstraction in a C++ class?

  1. A

    It ensures that every data member is public.

  2. B

    It exposes essential operations while hiding unnecessary implementation details.

  3. C

    It requires every class to inherit from another class.

  4. D

    It replaces member functions with global functions.

02
Choose one
1 point

A Car needs to start an Engine but is not a specialized kind of Engine. Which design most directly models this relationship?

  1. A

    Make Car publicly inherit from Engine.

  2. B

    Copy the implementation of Engine into Car.

  3. C

    Store an Engine object as a member of Car.

  4. D

    Make Engine a friend of Car without storing one.

03
Choose one
1 point

Which design best expresses a genuine substitutable relationship between Circle and Shape?

  1. A

    A Circle publicly inherits from Shape and implements the Shape interface.

  2. B

    A Circle privately stores a Shape solely to reuse its data layout.

  3. C

    A Circle exposes all of Shape's private members directly.

  4. D

    A Circle duplicates Shape's functions without any relationship between the types.

04
Choose all
1 point

Which two features are appropriate for a C++ base class intended to serve as a polymorphic interface? Select all correct choices.

  1. A

    A public pure virtual function such as area() = 0

  2. B

    A nonvirtual data member containing a concrete shape

  3. C

    A virtual destructor

  4. D

    A private constructor that prevents every derived class from constructing objects

05
Choose all
1 point

Which two statements correctly describe the benefits of runtime polymorphism in the Shape and print_area example? Select all correct choices.

  1. A

    The caller must know the concrete class before calling area.

  2. B

    The caller can use a Shape reference while the concrete override is selected at runtime.

  3. C

    The base class must contain the complete implementation of every shape's area.

  4. D

    A new derived shape can work with the existing function if it implements the required interface.

06
True or false
1 point

In C++, members of a class are public by default.

  1. A

    True

  2. B

    False

07
True or false
1 point

Passing a polymorphic derived object by value as a base object can cause object slicing.

  1. A

    True

  2. B

    False

08
Written response
1 point

What C++ keyword can be placed after Circle::area to ask the compiler to verify that it overrides a virtual function from Shape?

09
Written response
1 point

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?

10
Fill in the blank
1 point

A relationship in which one object contains another object as a member is commonly called a relationship.

11
Fill in the blank
1 point

In the declaration virtual double area() const ;, what notation marks area as a pure virtual function?

12
Open ended
1 point

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.

13
Choose one
1 point

In the Document example, which interface design best lets clients save a document without depending on validation or storage details?

  1. A

    Expose validate and write_to_disk so callers can control the storage sequence.

  2. B

    Expose save while keeping validate and write_to_disk private.

  3. C

    Make every helper protected so all unrelated callers can use it.

  4. D

    Replace save with direct access to the document's storage representation.

14
Choose one
1 point

What is the most accurate description of the role of protected members in a C++ class hierarchy?

  1. A

    Protected members are intended for the class and its derived classes.

  2. B

    Protected members are accessible only to unrelated callers.

  3. C

    Protected members are always more encapsulated than private members.

  4. D

    Protected members automatically become public in every derived class.

15
Choose one
1 point

In the C++ example, what is the relationship between BankAccount and account?

  1. A

    BankAccount is an object, and account is a class.

  2. B

    BankAccount is a class, and account is an object.

  3. C

    Both BankAccount and account are objects.

  4. D

    Both BankAccount and account are classes.

16
Choose one
1 point

Which design choice most directly demonstrates abstraction in the BankAccount example?

  1. A

    Making every data member public so callers can inspect it.

  2. B

    Combining several unrelated classes into one larger class.

  3. C

    Exposing essential operations while hiding unnecessary implementation details.

  4. D

    Replacing all member functions with global functions.

17
Choose one
1 point

In the given C++ design, why is Car an example of composition?

  1. A

    Car contains an Engine object as a member.

  2. B

    Car publicly inherits from Engine.

  3. C

    Engine is a derived class of Car.

  4. D

    Car and Engine are unrelated because start is called indirectly.

18
True or false
1 point

True or false: Because Shape declares area() as a pure virtual function, client code cannot create a Shape object directly.

  1. A

    True

  2. B

    False

19
Written response
1 point

What C++ mechanism causes print_area(circle) to call Circle::area() when print_area receives a Shape reference?

20
Written response
1 point

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?