Java Modifiers are used as keywords , which can be added to the definitions to change their meanings.
There are two types of modifiers which can be used in java .
1) Access Modifiers
2) Non Access Modifiers
First let us see about what are the Access Modifiers :
There are four types of access modifiers in java , which is used to control the classes, methods and variables .
1) Private(private)
2) Default(default)
3) Protected(protected)
4) Public(public)
Here we want to declare all the access modifiers in "Lowercase" letters as mentioned above in the bracket for all the modifiers.
Now lets as see the use of all the modifiers one by one .
private :
The private access modifier can be accessed only within the class
Example for the private modifier :
class test
{
private String testing = "testing";
}
default :
If there is no access modifier defined , then it will treated as default modifier.This can be accessible only with in the package .
Example for the default modifier :
class test
{
int testing =1;
}
protected :
The protected modifiers can is same as default modifier , can be accessed with in the package and other thing is , it can be accessed outside the package by using inheritance (Reuseability).
public :
This modifier can be accessible from everywhere.
Modifier
|
Within class
|
Within Package
|
Outside of the Package (by sub classes)
|
Outside of the Package
|
Private
|
Y
|
N
|
N
|
N
|
Default
|
Y
|
Y
|
N
|
N
|
Protected
|
Y
|
Y
|
Y
|
N
|
Public
|
Y
|
Y
|
Y
|
Y
|
Now let us see about Non access modifiers :
Here we have
1) static
2) final
3) abstract
as Non access modifiers , which can be used in classes , methods and variables as per the functionality we have .
Thanks ,
A M Balaji