Access Modifiers

Access Modifiers : Access modifiers are used to specify the visibility and accessibility of a class, member variables and methods.

Access Modifiers

Access Modifiers : Access modifiers are used to specify the visibility and accessibility of a class, member variables and methods.

Access Modifiers

Access Modifiers

     

Access Modifiers : Access modifiers are used to specify the visibility and accessibility of a class, member variables and methods. Java provides some access modifiers like: public, private etc.. These can also be used with the member variables and methods to specify their accessibility. 

  1. public keyword specifies that the public class, the public  fields and the public methods can be accessed from anywhere.
     
  2. private: This keyword provides the accessibility only within a  class i.e. private fields and methods can be accessed only within the same class.
      
  3. protected: This modifier makes a member of the class available to all classes in the same package and all sub classes of the class. 
      
  4. default : Its not a keyword. When we don't write any access modifier then default is considered. It allows the class, fields and methods accessible within the package only.