
Y – A member declared with ‘protected’ access modifier CAN be accessed by the members of the ‘same class’.protected – CAN be accessed from ‘same package’ and a subclass existing in any package can access.įor better understanding, member level access is formulated as a table:įirst row should be interpreted as:.public and no modifier – the same way as used in class level.II) Member level access modifiers (java variables and java methods)Īll the four public, private, protected and no modifer is allowed.

If a class has ‘no modifer’, then it CAN ONLY be accessed from ‘same package’.If a class is ‘public’, then it CAN be accessed from ANYWHERE.Only two access modifiers is allowed, public and no modifier I) Class level access modifiers (java classes only) The two levels are class level access modifiers and member level access modifiers. Usage of these access modifiers is restricted to two levels. Using ‘no modifier’ is also sometimes referred as ‘package-private’ or ‘default’ or ‘friendly’ access. They are public, private, protected, no modifer (declaring without an access modifer). There are four access modifiers used in java.

Access modifiers specifies who can access them.
