Encapsulation in PHP- Tutorialpath

 

PHP Encapsulation
PHP Encapsulation

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.

Encapsulation
Encapsulation

Output:

Encapsulation output
Encapsulation output

Example:

Create a arithmetic class with add( ),sub( ),mult( ) and div( ) method

Encapsulation1
Encapsulation 1

Output:

Encapsulation output1
Encapsulation output1

2 thoughts on “Encapsulation in PHP- Tutorialpath

Leave a Reply to Md. Mahmud Cancel reply

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