Encapsulation is one of the four fundamental Object Oriented Concepts (OOP). The other three are inheritance, polymorphism, and abstraction.
Encapsulation in Java is a mechanism of wrapping the data and code acting on the data together as a single unit. In encapsulation, the variables of a class will be hidden …