As we all know java has below modifiers :
Class level Modifiers (only class) :
- public
- private
- protected
- no modifiers (package private)
Class level Modifiers (only class) :
- If a class is ‘public’, then it CAN be accessed from ANYWHERE.
- If a class has ‘no modifer’, then it CAN ONLY be accessed from ‘same package’.
- public and no modifier – the same way as used in class level.
- private – members CAN ONLY access.
- protected – CAN be accessed from ‘same package’ and a subclass existing in any package can access.
Access Modifiers |
Same Class | Same Package | Subclass | Other packages |
public | Y | Y | Y | Y |
protected | Y | Y | Y | N |
no access modifier | Y | Y | N | N |
private | Y | N | N | N |
No comments:
Post a Comment