Which statement best describes the relationship between a C++ class and an object?
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.
True or false: If pointer is a pointer to a Rectangle object, pointer->area() is equivalent to (*pointer).area().
- A
True
- B
False
What is the name of the :: operator used in a definition such as Counter::increment()?
Complete the statement: In a C++ class, members are by default.
Explain what the const after getBalance() means in the declaration double getBalance() const, and state one consequence for callers.
A Temperature class must prevent its stored Celsius value from falling below absolute zero. Which design best preserves that invariant?
- A
Keep the data member private and validate changes through a public member function.
- B
Make the data member public so all client code can update it directly.
- C
Store every value without checking it and validate only when displaying it.
- D
Use inheritance so unrelated code can access the data member.
Which three statements about C++ constructors are correct? Select all that apply.
- A
It has the same name as the class.
- B
It must return an object pointer.
- C
It has no return type.
- D
It is called automatically during object initialization.
Complete the statement: In C++, a constructor should commonly use a to initialize data members before the constructor body runs.
Why is explicit useful on the single-argument constructor explicit Distance(int meters)?
- A
It makes the constructor virtual.
- B
It prevents undesirable implicit conversion from the argument type.
- C
It forces every object to be dynamically allocated.
- D
It makes the stored value public.
What kind of destructor should a polymorphic base class generally provide when objects may be deleted through a base pointer?
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.
- A
True
- B
False
Which two statements correctly describe public inheritance in C++? Select all that apply.
- A
Public inheritance expresses an “is-a” relationship.
- B
A derived class can directly access every private member of its base class.
- C
A derived class may add new members or override virtual functions.
- D
Public inheritance requires the base class to have no data members.
Given the polymorphic classes in the material, what does makeSound(dog) print when dog is a Dog and makeSound takes a const Animal&?
- A
It prints "Some sound" because the parameter is declared as Animal.
- B
It prints nothing because a base reference cannot refer to a Dog.
- C
It prints "Woof" because the virtual call selects the derived override at runtime.
- D
It prints both "Woof" and "Some sound" automatically.
Which feature makes a C++ class abstract and prevents direct instantiation?
- A
It contains only private data members.
- B
It has at least one pure virtual function.
- C
It uses a member initializer list.
- D
It is always declared with struct instead of class.
What is the default access difference between a C++ struct and a C++ class?
- A
Members of a
structare private by default, and members of aclassare protected by default. - B
Members of a
structare public by default, and members of aclassare private by default. - C
Members of both are public by default.
- D
Members of both are private by default.
True or false: Writing a C++ class definition normally creates an object of that class immediately.
- A
True
- B
False
Which statement correctly describes a C++ constructor?
- A
It must return the newly created object.
- B
It must have a different name from the class.
- C
It has the same name as the class and no return type.
- D
It can be called only after the object has already been initialized.
What C++ operator is used in an expression such as Counter::increment() to identify a member being defined outside the class body?
What does the const qualifier after a member function's parameter list mean in the context of the BankAccount example?
- A
It can modify every private data member without restriction.
- B
It promises not to modify the object's observable state.
- C
It can be called only on dynamically allocated objects.
- D
It automatically makes every data member public.
What exact suffix declares a C++ virtual member function as pure virtual?
Related study packs and tools
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.