-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path9. HierarInheritance.php
More file actions
39 lines (39 loc) · 1.23 KB
/
9. HierarInheritance.php
File metadata and controls
39 lines (39 loc) · 1.23 KB
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
<?php
// Hierarchical Inheritance
class Father {
public $a;
public $b;
function getValue($x, $y){
$this->a = $x;
$this->b = $y;
}
}
class Son extends Father {
function add(){
return $this->a + $this->b;
}
function display(){
echo "Value of A: $this->a <br>";
echo "Value of B: $this->b <br>";
echo "Addition: " . $this->add() . "<br>";
// echo "Addition: $this->add()" This is Wrong Statement
}
}
class Daughter extends Father {
function multi(){
return $this->a * $this->b;
}
function disp(){
echo "Value of A: $this->a <br>";
echo "Value of B: $this->b <br>";
echo "Multiplication: " . $this->multi() . "<br>";
// echo "Multiplication: $this->multi()" This is Wrong Statement
}
}
$objs = new Son; // creating Son Class Object objs
$objd = new Daughter; // creating Daughter Class Object objd
$objs->getValue(40, 50); // Calling Father Class Function by Son's objs
$objs->display(); // Calling Son's Own Function
$objd->getValue(10, 20); // Calling Father Class Function by Daughter's objd
$objd->disp(); // Calling Daughter's own function
?>