order of access controls in java code example

Example 1: access modifiers in java

In Java, access specifiers are the keywords which are used to define 
the access scope of the method, class, or a variable. 
  In Java, there are four access specifiers.
  
  * Public: The classes, methods, or variables which are defined as public, 
  can be accessed by any class or method.
  * Protected: Protected can be accessed by the class of the same package, 
or by the sub-class of this class, or within the same class.
  * Default: Default are accessible within the package only. 
    By default, all the classes, methods, and variables are of default scope.
  * Private: The private class, methods, or variables defined as private 
    can be accessed within the class only

Example 2: What access modifiers can be used for class

We can use only two access modifiers for class public and default.
public: A class with public modifier can be visible
1) In the same class
2) In the same package subclass
3) In the same package nonsubclass
4) In the different package subclass
5) In the different package non subclass.
default : A class with default modifier can be accesed
1) In the same class
2) In the same package subclass
3) In the same package nonsubclass
4) In the different package subclass
5) In the different package non subclass.

Tags:

Java Example