Binding data and code together into a single unit is known as encapsulation.
Java class is the best example of encapsulation.
For example, programmer are writing employee and student classes with same variables id and name. Also they can write same method display in both classes. It is possible to store different data in the variables. The data of one class will not spoil of another class.