Which description best captures the practice of encapsulation?
3 Encapsulation and Information Hiding Online Quiz Questions
Use this free practice quiz with 20 questions to review 3 Encapsulation and Information Hiding, test your knowledge, and prepare for your next test or exam.
True or false: Information hiding and encapsulation are related, but information hiding specifically focuses on concealing implementation details that clients do not need to know.
- A
True
- B
False
What access level should a field use when it must be available only within its declaring class or type?
A(n) is a condition that should remain true for every valid object.
Which design best preserves encapsulation for a temperature value that must not be below -273.15 degrees Celsius?
- A
A private field with a controlled setter that rejects values below -273.15
- B
A public field so every caller can update the temperature directly
- C
A public field together with a comment telling callers to validate values
- D
A private field with no operation for reading or changing the temperature
True or false: A property with a public getter and private setter allows client code to read a value while preventing arbitrary replacement of that value.
- A
True
- B
False
In the Thermostat example, what is the maximum allowed target temperature? Enter the value in degrees Celsius.
Select all benefits that the material directly associates with encapsulation.
- A
Protecting object state from invalid changes
- B
Hiding complicated implementation details
- C
Allowing any caller to modify fields without restrictions
- D
Reducing dependencies between classes
A Playlist can expose operations such as addSong and playNext without revealing whether its songs are stored in a . Concealing that implementation decision illustrates .
Where should validation normally occur to ensure that an object's invariant is maintained?
- A
Only in documentation for the class
- B
Only in code that calls the class
- C
At the constructor, setter, factory method, or domain operation that changes the state
- D
Only after an invalid value has already been stored
Select all practices that support a clear public interface.
- A
Use operations that express the object's responsibility
- B
Minimize the public surface
- C
Require callers to know which internal algorithm is used
- D
Return suitable abstractions instead of unnecessary concrete implementation details
Explain why replacing a public mutable field with private state and controlled operations usually improves both encapsulation and information hiding. Include what happens to validation, object invariants, and client code when the internal representation changes.
Which statement correctly describes a property that exposes a FullName value?
- A
A property must always correspond directly to one stored field
- B
A property may compute a value from other object data
- C
A property cannot have different visibility for its accessors
- D
A property is the same as a public mutable field
True or false: Returning an object's actual internal mutable list is risky because callers can modify it without passing through the object's validation or control logic.
- A
True
- B
False
Which design best encapsulates a bank account whose balance must never become negative?
- A
public balance with unrestricted assignment
- B
private balance with validated deposit and withdraw operations
- C
public balance with validation documented for callers
- D
private balance with no operations for changing it
A field is used only by methods in its declaring class. Which access level best follows the recommended default for access control?
- A
public
- B
protected
- C
private
- D
package-, module-, or assembly-level access
A User object's email should be readable by client code but replaceable only through the class's validation logic. Which property design is most appropriate?
- A
a public field
- B
a public getter and public setter with no validation
- C
a private getter and public setter
- D
a public getter and private setter
Where should a class validate a value that must satisfy an invariant whenever it enters or changes the object?
- A
inside the object's constructor or state-changing operation
- B
only in documentation for client programmers
- C
only in the method that later reads the value
- D
in every client that happens to use the object
Which access modifier makes a member available only within its declaring class or type?
What is the technical term for a condition that should remain true for every valid object?
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.