Encapsulation is a concept of wrapping up or binding up related data members and methods in a single module is known as encapsulation
And hiding the essential internal property of that module known as data abstraction.
Private method means it can be accessed within same class. Outside, Class can’t access private method of other class.That’s why encapsulation is known as data hiding is the main advantage for encapsulation.
Second advantage of encapsulation is you can make the class read only or write only by providing setter or getter method.
Output:
Example:
Create a arithmetic class with add( ),sub( ),mult( ) and div( ) method
Output:
That’s a cool example. Thumbs up!
Thank you Mahmud