Instantiation provide a mechanism of OOP to use to class's again and again.
OR
To use data-member or member function, we have to create an instance of the class.
Following are the example to create the object of class in different types
class Emp{ public $totalEmp; function __construct($totalEmp=10){ $this->totalEmp = $totalEmp; } function setTotalEmp($totalEmp){ $this->totalEmp = $totalEmp; } function getTotalEmp($totalEmp){ return $this->totalEmp; } } /** first way to create obj **/ $emp1 = new Emp; echo $emp1->totalEmp; echo ' '; /** second way to create obj **/ $emp2 = new Emp(); echo $emp2->totalEmp; echo ' '; /** third way to create obj **/ $emp3 = new Emp(30); echo $emp3->totalEmp;
No comments:
Post a Comment