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.

prowessapps.in prowessapps.in

prowessapps.in Note :
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.

Next topic is abstraction


Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at info@prowessapps.in

Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at info@prowessapps.in


(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved