Java OCA OCP Practice Question 1706

Question

Which statement is true about the accessibility of members?.

Select the one correct answer.

  • (a) A private member is always accessible within the same package.
  • (b) A private member can only be accessed within the class of the member.
  • (c) A member with default accessibility can be accessed by any subclass of the class in which it is declared.
  • (d) A private member cannot be accessed at all.
  • (e) Package/default accessibility for a member can be declared using the keyword default.


(b)

Note

A private member is only accessible within the class of the member.

If no accessibility modifier has been specified for a member, the member has default accessibility, also known as package accessibility.

The keyword default is not an accessibility modifier, and its only use is as a label in a switch statement.

A member with package accessibility is only accessible from classes in the same package.

Subclasses in other packages cannot access a member with default accessibility.




PreviousNext

Related