India: +91-4446 311 234 US: +1-6502 652 492 Whatsapp: +91-7530 088 009
Upto 20% Scholarship On Live Online Classes

Access Modifier in java

In Java, access modifiers are keywords that are used to control the access level of classes, methods, and variables. There are four types of access modifiers in Java:

  1. public: A class, method, or variable that is declared public can be accessed from any other class or package.
  2. private: A class, method, or variable that is declared private can only be accessed within the same class.
  3. protected: A class, method, or variable that is declared protected can be accessed within the same package or by a subclass in a different package.
  1. default (also known as package-private): A class, method, or variable that has no access modifier specified is considered to have default access and can be accessed within the same package.

By default, all class and interface members have package level access

java training in coimbatore will help students to understand the object-oriented programming in a better way. They will get an understanding of how to write a program using Java. The course also includes a session on how to debug programs written in Java.


Encapsulation in Java is the process of wrapping data and methods together in a single unit called an object. This ensures that the internal state of an object is protected from external access and modification. Encapsulation is achieved by using access modifiers (such as private, public, protected, and default) to restrict access to the members of a class.

For example, a class may have private variables that can only be accessed and modified by methods within the same class, while the class provides public methods for interacting with the private data. This allows the class to control how its internal state is accessed and modified, and prevents external code from directly manipulating the state of an object in an unintended way.

Encapsulation also allows for the implementation of an object to change without affecting the code that uses the object, making the code more robust and easier to maintain.

Encapsulation is one of the fundamental principles of Object-Oriented Programming (OOP) along with inheritance and polymorphism.