Java Access Modifiers

Java access modifiers are used to set the accessibility of class, method, constructor and variable.

There are two types of modifiers in Java:

  1. access modifiers → private, default, protected and public
  2. non-access modifiers → abstract, static, final, volatile, transient etc.

Below are the four access modifiers:


private variables and methods can be access within the same class only.

Note: In this above example, it is not allowed to use variable ‘a’ outside of Count class.


The default access modifier uses with in the package. Default access modifier for class, methods and variable will be default if we explicitly don’t define.


protected variable or method can only be access inside the sub class or same package. In the below code ‘a’ will not be accessible if TestClass class not extends Count class.


The public access modifier can be access from anywhere.

Imran Khan

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan