Advertisement
Yousuf1791

inheritance-oop

May 14th, 2023
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. class employee{
  4.     public $name;
  5.     public $age;
  6.     public $salary;
  7.  
  8.     function __construct($n, $a, $s){
  9.         $this->name = $n;
  10.         $this->age = $a;
  11.         $this->salary = $s;
  12.     }
  13.  
  14.     function info(){
  15.         echo "<h3>Employee info</h3><br>";
  16.         echo "Employee name : ".$this->name."<br>";
  17.         echo "Employee age : ".$this->age."<br>";
  18.         echo "Employee salary : ".$this->salary."<br>";
  19.     }
  20. }
  21.  
  22. class manager extends employee{
  23.     public $ta = 1000;
  24.     public $phone_bill = 300;
  25.     public $total_salary;
  26.  
  27.     function info(){
  28.         $this->total_salary = $this->salary + $this->ta + $this->phone_bill;
  29.         echo "<h3>Manager info</h3><br>";
  30.         echo "Manager name : ".$this->name."<br>";
  31.         echo "Manager age : ".$this->age."<br>";
  32.         echo "Manager salary : ".$this->total_salary."<br>";
  33.     }
  34.  
  35. }
  36.  
  37. $e1 = new employee("Emran", 21, "5000");
  38. $e1->info();
  39.  
  40. $e2 = new manager("Yousuf", 23, "10000");
  41. $e2->info();
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement