A class design requires that a particular member variable must be accessible by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this?

A class design requires that a particular member variable must be accessible by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this?


A. The variable should be marked public.
B. The variable should be marked private.
C. The variable should be marked protected.
D. The variable should have no special access modifier.
E. The variable should be marked private and an accessor method provided.

The correct answer is C

Explanation: See the section on the protected modifier.


Java

Learn More Multiple Choice Question :