Free Practice Quiz Question List

8 Classes and Introductory Object-Oriented Programming Online Quiz Questions

Use this free practice quiz with 20 questions to review 8 Classes and Introductory Object-Oriented Programming, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

Which statement best describes the relationship between a C++ class and an object?

  1. A

    The class definition always creates one object immediately.

  2. B

    An object is created when the class is instantiated.

  3. C

    A class can contain only data members, not functions.

  4. D

    An object must always be created with new.

02
True or false
1 point

True or false: If pointer is a pointer to a Rectangle object, pointer->area() is equivalent to (*pointer).area().

  1. A

    True

  2. B

    False

03
Written response
1 point

What is the name of the :: operator used in a definition such as Counter::increment()?

04
Fill in the blank
1 point

Complete the statement: In a C++ class, members are by default.

05
Open ended
1 point

Explain what the const after getBalance() means in the declaration double getBalance() const, and state one consequence for callers.

06
Choose one
1 point

A Temperature class must prevent its stored Celsius value from falling below absolute zero. Which design best preserves that invariant?

  1. A

    Keep the data member private and validate changes through a public member function.

  2. B

    Make the data member public so all client code can update it directly.

  3. C

    Store every value without checking it and validate only when displaying it.

  4. D

    Use inheritance so unrelated code can access the data member.

07
Choose all
1 point

Which three statements about C++ constructors are correct? Select all that apply.

  1. A

    It has the same name as the class.

  2. B

    It must return an object pointer.

  3. C

    It has no return type.

  4. D

    It is called automatically during object initialization.

08
Fill in the blank
1 point

Complete the statement: In C++, a constructor should commonly use a to initialize data members before the constructor body runs.

09
Choose one
1 point

Why is explicit useful on the single-argument constructor explicit Distance(int meters)?

  1. A

    It makes the constructor virtual.

  2. B

    It prevents undesirable implicit conversion from the argument type.

  3. C

    It forces every object to be dynamically allocated.

  4. D

    It makes the stored value public.

10
Written response
1 point

What kind of destructor should a polymorphic base class generally provide when objects may be deleted through a base pointer?

11
True or false
1 point

True or false: A C++ class with at least one pure virtual function can be instantiated directly as long as the pure virtual function has a declaration.

  1. A

    True

  2. B

    False

12
Choose all
1 point

Which two statements correctly describe public inheritance in C++? Select all that apply.

  1. A

    Public inheritance expresses an “is-a” relationship.

  2. B

    A derived class can directly access every private member of its base class.

  3. C

    A derived class may add new members or override virtual functions.

  4. D

    Public inheritance requires the base class to have no data members.

13
Choose one
1 point

Given the polymorphic classes in the material, what does makeSound(dog) print when dog is a Dog and makeSound takes a const Animal&?

  1. A

    It prints "Some sound" because the parameter is declared as Animal.

  2. B

    It prints nothing because a base reference cannot refer to a Dog.

  3. C

    It prints "Woof" because the virtual call selects the derived override at runtime.

  4. D

    It prints both "Woof" and "Some sound" automatically.

14
Choose one
1 point

Which feature makes a C++ class abstract and prevents direct instantiation?

  1. A

    It contains only private data members.

  2. B

    It has at least one pure virtual function.

  3. C

    It uses a member initializer list.

  4. D

    It is always declared with struct instead of class.

15
Choose one
1 point

What is the default access difference between a C++ struct and a C++ class?

  1. A

    Members of a struct are private by default, and members of a class are protected by default.

  2. B

    Members of a struct are public by default, and members of a class are private by default.

  3. C

    Members of both are public by default.

  4. D

    Members of both are private by default.

16
True or false
1 point

True or false: Writing a C++ class definition normally creates an object of that class immediately.

  1. A

    True

  2. B

    False

17
Choose one
1 point

Which statement correctly describes a C++ constructor?

  1. A

    It must return the newly created object.

  2. B

    It must have a different name from the class.

  3. C

    It has the same name as the class and no return type.

  4. D

    It can be called only after the object has already been initialized.

18
Written response
1 point

What C++ operator is used in an expression such as Counter::increment() to identify a member being defined outside the class body?

19
Choose one
1 point

What does the const qualifier after a member function's parameter list mean in the context of the BankAccount example?

  1. A

    It can modify every private data member without restriction.

  2. B

    It promises not to modify the object's observable state.

  3. C

    It can be called only on dynamically allocated objects.

  4. D

    It automatically makes every data member public.

20
Written response
1 point

What exact suffix declares a C++ virtual member function as pure virtual?