Computer Applications
Explain visibility in terms of the following access modifiers:
- public
- private
- protected
- no modifier specified
Encapsulation & Inheritance in Java
6 Likes
Answer
- public — The class members declared with the public access specifier can be accessed from outside the class.
- private — The class members declared with the private access specifier can be accessed only within the class in which they are declared.
- protected — The class members declared with the protected access specifier can be accessed within the same package only. They are not accessible from outside the package, except if the sub class is in the other package.
- no modifier specified — When no access specifier is mentioned, then by default that members of a class are public within the package. They can be accessed within the same package but not outside the package.
Answered By
5 Likes