Java OCA OCP Practice Question 1901

Question

Select the correct order of restrictiveness for access modifiers...

First one should be least restrictive

Select 1 option

  • A. public < protected < package (i.e. no modifier) < private
  • B. public < package (i.e. no modifier) < protected < private
  • C. public < protected < private < package (i.e. no modifier)
  • D. protected < package (i.e. no modifier) < private < public
  • E. depends on the implementation of the class or method.


Correct Option is  : A

Note

Members with default accessibility are only accessible within the class itself and from classes in the same package.

Protected members are in addition accessible from subclasses.

Members with private accessibility are only accessible within the class itself.




PreviousNext

Related