Question 426 of 513
1Z0-829 Utilizing Java Object-Oriented Approach Practice Question
A developer writes a class `Employee` with a private field `salary`. Which approach correctly allows subclasses to access `salary` directly without breaking encapsulation?
⚠ Common exam trap
A common mix-up: candidates confuse 'direct access' with 'access via a getter' and select option D, missing the explicit requirement for direct field access without a method call.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Change `salary` to protected.
The `protected` access modifier allows direct access to the `salary` field by subclasses (via inheritance) while still preventing access from unrelated classes outside the package. This strikes the balance between encapsulation (restricting access to the class hierarchy) and the requirement for subclass direct access.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use package-private access (no modifier).
Why it's wrong here
Package-private does not allow access from subclasses in different packages.
- ✗
Make `salary` public.
Why it's wrong here
Public access breaks encapsulation entirely.
- ✓
Change `salary` to protected.
Why this is correct
Protected access allows subclasses to access the field directly.
- ✗
Keep `salary` private and add a public getter method.
Why it's wrong here
A getter provides indirect access only, not direct field access.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 25, 2026
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.