Encapsulation in Java
Encapsulation is one of the four fundamental Object Oriented Programming concepts ( The other three are inheritance, polymorphism, and abstraction).
Encapsulation is a process of wrapping of state (variables) and behavior (methods) in a single ( object ) unit.
Data encapsulation is the important OOP concept of data hiding.
In encapsulation the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class.
Therefore "Encapsulation" is also known as a way of "Data Hiding" .
Benefits of Encapsulation :
The fields of a class can be made read-only or write-only.
A class can have total control over what is stored in its fields.
The users of a class do not know how the class stores its data.
To achieve encapsulation in Java
Declare the variables of a class as private.
Provide public setter and getter methods to modify and view the variables values.
The Java Bean class is the example of fully encapsulated class.
1. Encapsulation and data hiding are used synonymously everywhere but It should not be misunderstood that encapsulation is all about data hiding only.
2. When we say encapsulation, emphasis should be on grouping or packaging or bundling related data and behavior together.
Training For College Campus
We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.
Please mail your requirement at firstname.lastname@example.org
Projects For Students
Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.
Students can mail requirement at email@example.com