-
Notifications
You must be signed in to change notification settings - Fork 4
/
inheritance.php
50 lines (40 loc) · 1.22 KB
/
inheritance.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
echo "What is Inheritance?<br>";
class Employee{
public $name = "harry";
private $salary = 12000;
private $grade = 3;
function setSalary($salary){
$this->salary = $salary;
}
function getSalary(){
echo "The salary of employee is $this->name is $this->salary <br>";
}
function showName(){
echo "The name of this employee is $this->name <br>";
}
}
// Inheriting a new class Programmer from Employee
class Programmer extends Employee{
private $language = "php";
function changeLanguage($lang){
$this->language = $lang;
// echo $this->grade; --> This will throw an error because grade is private in the parent class
}
}
$rohan = new Employee();
$rohan->name = "Rohan";
$rohan->setSalary(100);
$rohan->getSalary();
$rohan->showName();
$shubham = new Employee();
$shubham->name = "Shubham";
$shubham->setSalary(10000000);
$shubham->getSalary();
$shubham->showName();
$geeta = new Programmer();
$geeta->name = "Geeta";
echo $geeta->changeLanguage("Python");
$geeta->getSalary();
$geeta->showName();
?>