Access specifiers in java :
Access specifiers in java classified into four types for the members. Access specifiers place a very important
role in real time java applications. While developing the application we are defined the members which are
visible outside of the class and which should not visible out side of the package. Suppose in some scenarios
we strictly hide some of the members which are only visible in side the class and the members which should
not visible any of the other classes.
- Private
- Default
- Protected
- Public
In a same class we can access all the other members of a class directly irrespective of the access specifiers.
Private access specifier :
The visibility of the private access specifier is only with in the class. we can not access the private access
specifiers outside of the class.
Example :
public class Test{
private int value = 10;
}
Public access specifier :
If we declares the members of a class as public, it can be accessible any where. I mean it can be accessible
inside the class, outside the class, outside of the other packages.
Example :
public class Test{
public int value = 10;
}
Protected access specifier :
If we declares the members of a class as protected, it can be accessible with in the same package
and sub classes of outside the package.
Example :
public class Test{
protected int value = 10;
}
Default access specifier :
If we declares the members of a class as Default, it can be accessible with in the same package
and sub classes of the same package
We can not any access specifier for default.
Example :
public class Test{
int value = 10;
}
0 comments:
Post a Comment