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
- Flashcards
02 — Information and Representation
Learn how computers encode numbers, text, images, and sound as binary data, along with the limits and trade-offs of digital representation.
- Quiz
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
- Flashcards
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
- Quiz
3 Conditional Control Flow
A medium-difficulty quiz on Python conditional control flow, including branching, comparison and logical operators, truthiness, short-circuit evaluation, nesting, and common syntax mistakes.
- Study guide
3 CPU Architecture
Learn how registers, the ALU, datapath connections, and control logic work together to fetch and execute CPU instructions.
- Study guide
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.
Programming in Java - CS 102Updated - Study guide
05 — Data Structures: Concepts, Operations, and Trade-Offs
A structured guide to the main data structures, their operations, efficiency trade-offs, representations, and practical selection criteria.
- Quiz
06 — Algorithms and Correctness
A medium-difficulty assessment of algorithm specifications, searching, sorting, iteration, recursion, invariants, termination, and correctness proofs. Questions progress from direct application to integrated reasoning.
- Study guide
07 — Efficiency and Computational Complexity
A progressive guide to measuring algorithmic time and memory requirements, interpreting asymptotic bounds, analyzing common code patterns, and balancing performance trade-offs.
- Study guide
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.
- Flashcards
08 — Discrete Mathematics for Computer Science
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
- Study guide
10 — Data, Systems, and Applications
A progression through how data is organized, searched, exposed through software interfaces, and managed through abstraction layers in modern computer systems.