Header Ads

Access Modifiers in java | Class 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."
 


Steps to Subscribe my blog in 15 secs:
1. Enter your mail id in "Subscribe" box.
2. Enter Captcha for verification.
3. A mail will be received with link in your mail id.Just Click on link  and  then Done .Thank you for subscribing :)


No comments

Note: Only a member of this blog may post a comment.