We can use all access modifiers public, private, protected and default for variables.
public : When a variables is declared as public it can be accessed
1) In the same class
2) In the same package subclass
3) In the same package non subclass
4) In the different package subclass
5) In the different package non subclass.
default : When a variables is declared as default, we can access that method in
1) In the same class
2) In the same package subclass
3) In the same package non subclass
We cannot access default access variables in
4) Different package subclass
5) Different package non subclass.
protected : When a variables is declared as protected it can be accessed
1) With in the same class
2) With in the same package subclass
3) With in the same package non subclass
4) With in different package subclass
It cannot be accessed non subclass in different package.
private : When a variables is declared as private it can be accessed only in that class.
It cannot be accessed in
1) Same package subclass
2) Same package non subclass
3) Different package subclass
4) Different package non subclass
Leave a Reply