Java OCA OCP Practice Question 2319

Question

Select the correct option.

  • a The declaration of private variables to store the state of an object is encouraged.
  • b The protected members of a class aren't accessible outside the package in which the class is defined.
  • c The public members of a class that's defined with default access can be accessed outside the package.
  • d If you change the signature or implementation of a private method, other classes that use this method cease to compile.


a

Note

Option (b) is incorrect because the protected members of a class are accessible by the derived classes, outside the package in which the class is defined.

Option (c) is incorrect because a class with default access isn't visible outside the package within which it's defined.

If the class isn't visible itself, it doesn't matter whether its members are accessible or not.

Option (d) is incorrect because a private method can't be used outside the class in which it's defined.




PreviousNext

Related