Samarth Polytechnic Belhe: Department of Computer Engineering
Samarth Polytechnic Belhe: Department of Computer Engineering
Subject : Web Based application development using PHP. Subject code : 22619
Experiment No: 8
Theory:
1.0 Title:
3. Hierarchical
inheritance class A
extends B
{
…………………………
………………………
}
class C extends B
{
……………………..
…………………………
}
4. Multiple inheritance
Not supported by PHP. But it can be achieved using trait keyword.
Program:-
<?php
class Fruit {
public $name;
public $color;
public function construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
public function intro() {
echo "The fruit is {$this->name} and the color is {$this->color}.";
}
}
// Strawberry is inherited from Fruit
class Strawberry extends Fruit {
public function message() {
echo "Am I a fruit or a berry? ";
}
}
Output:-
Constructor:
program:-
<?php
class Car{
public $name;
public $color;
function construct($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
Output:-