MCQ
Single Best Answer
Easy
QWe would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this ?
ID: #24250
Elements of Accounting
56 views
Question Info
#24250Q ID
EasyDifficulty
Elements of AccountingTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer: Option B
Explanation
Access modifiers in Java (for class members)
-
private → visible only inside the same class.
-
default (no keyword) → visible inside the same package only.
-
protected → visible inside the same package + visible in all subclasses (even if in a different package).
-
public → visible everywhere.
-
private protected → ❌ Not a valid keyword in Java.
Your question:
We want a member of a class visible in all subclasses, regardless of the package.
✅ That’s exactly what protected does.
Correct Answer:
(b) protected
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic