MCQ Practice Single Best Answer Topic: Elements of Accounting

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 ?

Question ID
#24250
Subchapter
Elements of Accounting
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A private
  • B protected
  • C public
  • D private protected
Correct 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

Share This Question

Share this MCQ with your friends or study group.