Inheritance

 <?php

class Employee
{
    public $name, $age, $salary;

    function __construct($n, $a, $s)
    {
        $this -> name = $n;
        $this -> age = $a;
        $this -> salary = $s;
    }
    function info()
    {
        echo "<h3>Employee Profile</h3>";
        echo "Employee Name : " . $this -> name . "<br>";
        echo "Employee Age : " . $this -> age . "<br>";
        echo "Employee Salary : " . $this -> salary . "<br>";
    }
}
class Manager extends Employee
{
    public $ta = 1000;
    public $phone = 200;
    public $totalSalary;

    function info()
    {
        $this -> totalSalary = $this->salary + $this->ta + $this->phone;

        echo "<h3>Manager Profile</h3>";
        echo "Employee Name : " . $this->name . "<br>";
        echo "Employee Age : " . $this->age . "<br>";
        echo "Employee Salary : " . $this->totalSalary . "<br>";
    }

}

$e1 = new Manager("Yahoo Baba", 21, 32000);
$e2 = new employee("Krishna", 27, 2000);

$e1 -> info();
$e2 -> info();

//  OUTPUT:
//Manager Profile
// Employee Name : Yahoo Baba
// Employee Age : 21
// Employee Salary : 33200
// Employee Profile
// Employee Name : Krishna
// Employee Age : 27
// Employee Salary : 2000
?>

Comments

Popular posts from this blog

Ajax Insert Records in Database Tutorial in PHP

SubQuery with EXISTS and NOT EXISTS in PHP

Submitting HTML Form data in JSON File (without MySql Database) in PHP