What are the access modifiers in Java
private: the members of the class are only accessible within the class. The service word private is used for designation.
default, package-private, package level (package level access): Visibility of the class/class members only inside the package. This is the default access modifier - no special designation is required.
protected: class members are available inside the package and in descendants. The service word protected is used for designation.
public: the class/members of the class are available to everyone. The service word public is used for designation.
A sequence of modifiers in ascending order of closeness: public, protected, default, private.
During inheritance, it is possible to change access modifiers towards greater visibility (to maintain compliance with Barbara Liskov's substitution principle).
Read also:
Comments
Post a Comment