Java Encapsulation

Encapsulation is one of four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction.

Encapsulation is the ability to package data and related behavior in an object bundle and control/restrict access to them (both data and function) from other objects. It is all about packaging related stuff together and hide them from external elements.

We should not misunderstood that encapsulation is all about data hiding only. When we say encapsulation, emphasis should be on grouping or packaging or bundling related data and behavior together.

When we design a class in OOP, the first principle we should have in mind is encapsulation. Group the related data and its behavior in a bucket. Primary benefit of encapsulation is, better maintainability.

Leave a Reply

Your email address will not be published. Required fields are marked *