Access Modifiers in java | Class Modifiers in java
Class Modifiers in java
Whenever we are writing our own classes compulsory we need to provide some information about our class to the jvm.
Like
1. Whether this class can be accessible from anywhere or not.
2. Whether child class creation is possible or not.
3. Whether is there any possibility of object creation or not etc.
We can do these by specifying this information by using the corresponding modifiers
The only applicable class modifiers for Top Level classes are as follows:
1. Public
2. Default
3. Final
4. Abstract
5. Strictfp
If we are using any other modifier then we will get compile time error.
Example:
private class Abc
{
public static void main(String args[])
{
int i=0;
for(int j=0;j<3;j++)
{
i=i+j;
}
System.out.println(i);
}
}
Output:
Compile time error.
But for the inner classes the following modifiers are allowed:
1. public
2. default
3. final
4. abstract
5. strictfp
6. private
7. protected
8. static
What is the difference between access specifier and access modifier?
1. In old languages 'C' or 'C++' public,private,protected,default are considered as access specifiers and all the remaining are considered as access modifiers.
2.But in java there is no such type of division all are considered as access modifiers.
An Inspirational quote:
"Whatever you are, be a good one."
Post a Comment