Java Tutorial: 9(Access Modifiers in JAVA)

Access Modifiers in JAVA defines the scope or the access level of that particular class or method.Classes, fields, constructors and methods can have one of four different Java access modifiers:

Start from here: JAVA Tutorial : Beginner 

  • private : The access level of a private modifier is only within the class. It cannot be accessed from outside the class.
  • default (package): The default Java access modifier is declared by not writing any access modifier at all. The default access modifier means that code inside the class itself as well as code inside classes in the same package as this class, can access the class, field, constructor or method which the default access modifier is assigned to.
  • protected : If a variable is declared as protected, then it can be accessed within the same package classes and sub-class of any other packages.Protected access modifier cannot be used for class and interfaces.
  • public: The Java access modifier public means that all code can access the class, field, constructor or method, regardless of where the accessing code is located. The accessing code can be in a different class and different package
Learn Salesforce: Salesforce DX : An Overview

Comments