Java OCA OCP Practice Question 1154

Question

Select the order of access modifiers from least restrictive to most restrictive.

  • A. public, private, protected, default
  • B. default, protected, private, public
  • C. public, default, protected, private
  • D. default, public, protected, private
  • E. public, protected, default, private


E.

Note

The public access modifier means the element is available to all.

protected lets those within the class, package, or subclass gain access to the element.

The lack of a modifier, that is, "default," means that it is accessible only within the package.

Finally, private is the most restrictive and provides access within the class only.




PreviousNext

Related