Bird
Raised Fist0

Which of the following statements about access modifiers and encapsulation is INCORRECT?

medium🐞 Bug Identification Q14 of Q15
OOP & Design Patterns - Encapsulation - Data Hiding, Getters/Setters & Access Modifiers
Which of the following statements about access modifiers and encapsulation is INCORRECT?
AProtected members are accessible by any class in the same package regardless of inheritance
BPrivate members are accessible only within the defining class
CPublic members are accessible from any other class
DUsing private access modifier enforces data hiding
Step-by-Step Solution
  1. Step 1: Recall access modifier rules

    Private: class-only; Protected: subclass and package; Public: everywhere.
  2. Step 2: Analyze Protected members are accessible by any class in the same package regardless of inheritance

    Protected members are accessible within the same package and subclasses, but not by any class in the package regardless of inheritance.
  3. Step 3: Validate other options

    Options B, C, and D correctly describe access modifiers and encapsulation.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Protected access is limited to subclasses and package, not all classes in package indiscriminately.
Quick Trick: Protected ≠ accessible by all classes in package, only subclasses and package [OK]
Common Mistakes:
MISTAKES
  • Confusing protected with package-private
  • Assuming private allows subclass access
  • Believing public restricts access
Trap Explanation:
PITFALL
  • Option A confuses protected and package-private access, a common misconception.
Interviewer Note:
CONTEXT
  • Checks precise understanding of access modifier scopes and their role in encapsulation.
Master "Encapsulation - Data Hiding, Getters/Setters & Access Modifiers" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes