Access Modifiers Table in Java  | Core Java Online Training

This Core Java Online Training “Access Modifiers Table in Java” is providing information about all the access modifiers in java and where we can access class members once we apply modifiers in java.


 

Access Modifiers in Java :

Access Modifiers in Java

 

private:

  • private member belongs to particular object(class).
  • We can’t apply to private modifier to class.
  • If we apply to class, complete object will be hidden from other objects. Hence no one can communicate with that object. Such type of objects is useless.
  • We can apply private functionality only to class members such as variable, methods & constructors.
  • Private members of class can be accessed only within that class in which those are defined.

 

public:

  • We can apply public modifier to class and its members.
  • public class can be accessed anywhere in java application.
  • In real time applications, all the classes must be defined as public.

 

<package>:

  • Can be applied to class members.
  • By default every class and its member is of package level.
  • It is the default access modifier in java application.
  • Package level members can be accessed only within the package.

 

protected:

  • Can be applied only to class members.
  • protected members can be accessed within the package and only from the sub classes of outer package.

 

Access Modifiers Table

Access Modifiers Table in Java

Share this