Java OCA OCP Practice Question 1240

Question

Assume there is a class Main with a protected variable. Methods in which class can access this variable?

  • A. Only subclasses of Main
  • B. Any subclass of Main or any class in the same package as Main
  • C. Only classes in the same package as Main
  • D. Any superclass of Main


B.

Note

The protected modifier allows access by any subclass or class that is in the same package, therefore Option B is the correct answer.




PreviousNext

Related