Wednesday 20 December 2017

Encapsulation in PHP (OOP)

Encapsulation in PHP (OOP)

Question: What is Encapsulation?
The wrapping up of "Data member" and "Member functions" into a single unit (called class) is known as encapsulation.

Question: Describe the Encapsulation?
Encapsulation means hiding the internal details of an object.
Encapsulation is a technique used to protect the information in an object from the other object.

Question: Give Example of the Encapsulation?
class Arithmetic {
    private $first = 10;
    private $second = 50;

    function add() {
        return $this->first + $this->second;

    function multiply() {
        return $this->first * $this->second;


//Create the object 
$obj = new Arithmetic( );

//Add Two number
echo $obj->add(); //60
//multiply Two number
echo $obj->multiply(); //500