Object-Oriented Programming · Question 16 · Easy

Object-Oriented Programming question 16

A Logger class keeps a list of log entries in a private field and offers only addEntry() and getEntries() (which returns a read-only copy). Which OOP principle does this design mainly demonstrate?

  1. Inheritance
  2. Polymorphism
  3. Encapsulation
  4. Multiple dispatch
Answer and explanation

Answer: C. Encapsulation

Explanation: Hiding the field and allowing access only through controlled methods is encapsulation: the class protects its own state. No subclassing (inheritance) or overriding (polymorphism) is involved.

Previous: Which SOLID principle states that objects of a subclass should be usable… · Next: Inside an instance method or constructor in Java, which keyword refers to the…

Practise object-oriented programming

Try a fresh set of object-oriented programming questions with an explanation after every answer, free and without signing up: Object-Oriented Programming practice. Or sit a full placement mock test.

More object-oriented programming questions

More technical & programming practice

DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge