Tag: accessibility

Questions Related to accessibility

Multiple choice accessibility
  1. A. Only Static methods of the same class

  2. B. Only instances of the same class

  3. C. Only methods those defined in the same class

  4. D. Only classes available in the same package.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Private attributes of a class can only be accessed by methods defined within the same class. This is encapsulation - private members are invisible outside the class boundary. Static methods are subject to the same rules as instance methods (no special access). Instances of the same class can't directly access private members of other instances. Classes in the same package have no special access to private members - they would need protected or package-private access modifiers.