1Z0-809 · Question #75
The protected modifier on a Field declaration within a public class means that the field ____________.
The correct answer is D. Can be read and written from this class and its subclasses defined in any package. protected grants access to the declaring class itself and to all subclasses regardless of which package they live in, plus any class within the same package - making D the accurate description. This is the key distinction Java draws between protected (cross-package via…
Question
Options
- ACannot be modified
- BCan be read but not written from outside the class
- CCan be read and written from this class and its subclasses only within the same package
- DCan be read and written from this class and its subclasses defined in any package
How the community answered
(30 responses)- B10% (3)
- C7% (2)
- D83% (25)
Explanation
protected grants access to the declaring class itself and to all subclasses regardless of which package they live in, plus any class within the same package - making D the accurate description. This is the key distinction Java draws between protected (cross-package via inheritance) and package-private (same-package only, no modifier).
Why the distractors are wrong:
- A is describing
final, which prevents reassignment, notprotected. - B describes a read-only pattern (like a
privatefield with only a getter) -protectedplaces no asymmetric restriction on reads vs. writes. - C is the most tempting trap: it correctly notes subclass access but wrongly confines subclasses to the same package. That would actually describe package-private (no modifier) behavior, not
protected.
Memory tip: Think of protected as "protecting the family tree." Any subclass - wherever it lives in the package hierarchy - inherits the right to use the field. If you have to stay in the same package, you don't need protected at all; just omit the modifier.
Community Discussion
No community discussion yet for this question.