Q: We 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 ?
-
A
private
-
B
protected
-
C
public
-
D
private protected
B
Answer:
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
Related Topic:
Share Above MCQ