<?php
class Dwarfs {
public $name;
public $behavior;
public function __construct($name, $behavior)
{
$this->name = $name;
$this->behavior = $behavior;
}
public function intro()
{
echo $this->name . '<br>';
echo $this->behavior . '<br><br>';
}
}
/* The class Dwarf is inherited from the class Dwarfs */
class Dwarf extends Dwarfs
{
public function message()
{
echo "A real famous dwarf:<br><br>";
}
}
$rd = '1 - Tyrion Lanister.';
$bh = '2 - played by Peter Dinklage.';
$Dwarf = new Dwarf($rd, $bh);
$Dwarf->message();
$Dwarf->intro();
?>
<?php
class Dwarfs {
public $name;
public $behavior;
public $friend;
public $age;
public function get_name()
{
return $this->name;
}
public function get_behavior()
{
return $this->behavior;
}
public function get_friend()
{
return $this->friend;
}
public function get_age()
{
return $this->age;
}
public function __construct($name, $behavior, $friend, $age)
{
$this->name = $name;
$this->behavior = $behavior;
$this->friend = $friend;
$this->age = $age;
}
public function intro()
{
echo $this->name . '<br><br>';
echo $this->behavior . '<br><br>';
echo $this->friend . '<br><br>';
echo $this->age . '<br><br>';
}
}
$nm = '1 - Happy.';
$bh = '2 - This dwarf is always cheerful and happy about everything.';
$fr = '3 - Snow White friend.';
$ag = '4 - 1937 - Year of the first performance of "Snow White and the Seven Dwarfs".';
$Dwarf_sw = new Dwarfs($nm, $bh, $fr, $ag);
echo $Dwarf_sw->get_name();
echo '<br><br>';
echo $Dwarf_sw->get_behavior();
echo '<br><br>';
echo $Dwarf_sw->get_friend();
echo '<br><br>';
echo $Dwarf_sw->get_age();
echo '<br><br><br>';
/* The class Dwarf is inherited from the class Dwarfs */
class Dwarf extends Dwarfs
{
public function message()
{
echo "A real famous dwarf:<br><br>";
}
}
$rd = '1 - Tyrion Lanister';
$bi = '2 - played by Peter Dinklage';
$fm = '3 - in "The Game of Thrones".';
$aa = '4 - Borned in June 11, 1969.';
$Dwarf = new Dwarf($rd, $bi, $fm, $aa);
$Dwarf->message();
$Dwarf->intro();
?>
<?php
class Dwarfs {
public $name;
public $behavior;
public $friend;
public $age;
public function get_name()
{
return $this->name;
}
public function get_behavior()
{
return $this->behavior;
}
public function get_friend()
{
return $this->friend;
}
public function get_age()
{
return $this->age;
}
public function __construct($name, $behavior, $friend, $age)
{
$this->name = $name;
$this->behavior = $behavior;
$this->friend = $friend;
$this->age = $age;
}
/* - - - - - - - - - - - - - - -
A T T E N T I O N
- - - - - - - - - - - - - - - */
protected function intro()
{
echo $this->name . '<br><br>';
echo $this->behavior . '<br><br>';
echo $this->friend . '<br><br>';
echo $this->age . '<br><br>';
}
}
$nm = '1 - Happy.';
$bh = '2 - This dwarf is always cheerful and happy about everything.';
$fr = '3 - Snow White friend.';
$ag = '4 - 1937 - Year of the first performance of "Snow White and the Seven Dwarfs".';
$Dwarf_sw = new Dwarfs($nm, $bh, $fr, $ag);
echo $Dwarf_sw->get_name();
echo '<br><br>';
echo $Dwarf_sw->get_behavior();
echo '<br><br>';
echo $Dwarf_sw->get_friend();
echo '<br><br>';
echo $Dwarf_sw->get_age();
echo '<br><br><br>';
/* The class Dwarf is inherited from the class Dwarfs */
class Dwarf extends Dwarfs
{
public function message()
{
echo "A real famous dwarf:<br><br>";
}
}
$rd = '1 - Tyrion Lanister';
$bi = '2 - played by Peter Dinklage';
$fm = '3 - in "The Game of Thrones".';
$aa = '4 - Borned in June 11, 1969.';
$Dwarf = new Dwarf($rd, $bi, $fm, $aa);
$Dwarf->message();
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The result of message() will be displayed
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$Dwarf->intro();
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The result of intro() will not be displayed
because its visibility is protected.
An ERROR will be issued.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
?>
DO THE TEST YOURSELF
Study the displayed data carefully
<?php
class Dwarfs {
public $name;
public $behavior;
public $friend;
public $age;
public function get_name()
{
return $this->name;
}
public function get_behavior()
{
return $this->behavior;
}
public function get_friend()
{
return $this->friend;
}
public function get_age()
{
return $this->age;
}
public function __construct($name, $behavior, $friend, $age)
{
$this->name = $name;
$this->behavior = $behavior;
$this->friend = $friend;
$this->age = $age;
}
/* - - - - - - - - - - - - - - -
A T T E N T I O N
- - - - - - - - - - - - - - - */
protected function intro()
{
echo $this->name . '<br><br>';
echo $this->behavior . '<br><br>';
echo $this->friend . '<br><br>';
echo $this->age . '<br><br>';
}
}
$nm = '1 - Happy.';
$bh = '2 - This dwarf is always cheerful and happy about everything.';
$fr = '3 - Snow White friend.';
$ag = '4 - 1937 - Year of the first performance of "Snow White and the Seven Dwarfs".';
$Dwarf_sw = new Dwarfs($nm, $bh, $fr, $ag);
echo $Dwarf_sw->get_name();
echo '<br><br>';
echo $Dwarf_sw->get_behavior();
echo '<br><br>';
echo $Dwarf_sw->get_friend();
echo '<br><br>';
echo $Dwarf_sw->get_age();
echo '<br><br><br>';
class Dwarf extends Dwarfs
{
/* - - - - - - - - - - - - - - -
A T T E N T I O N
- - - - - - - - - - - - - - - */
public function message()
{
echo "A real famous dwarf:<br><br>";
$this->intro();
}
}
$rd = '1 - Tyrion Lanister';
$bi = '2 - played by Peter Dinklage';
$fm = '3 - in "The Game of Thrones".';
$aa = '4 - Borned in June 11, 1969.';
$Dwarf = new Dwarf($rd, $bi, $fm, $aa);
$Dwarf->message();
?>
<?php
class Dwarfs {
public $name;
public $behavior;
public $friend;
public $age;
public function __construct($name, $behavior, $friend, $age)
{
$this->name = $name;
$this->behavior = $behavior;
$this->friend = $friend;
$this->age = $age;
}
public function intro()
{
echo $this->name . '<br><br>';
echo $this->behavior . '<br><br>';
echo $this->friend . '<br><br>';
echo $this->age . '<br><br>';
}
}
class Dwarf extends Dwarfs {
public $height;
public $weight;
public function __construct($name, $behavior, $friend, $age, $height, $weight)
{
$this->name = $name;
$this->behavior = $behavior;
$this->friend = $friend;
$this->age = $age;
$this->height = $height;
$this->weight = $weight;
}
public function intro()
{
echo $this->name . '<br><br>';
echo $this->behavior . '<br><br>';
echo $this->friend . '<br><br>';
echo $this->age . '<br><br>';
echo $this->height . '<br><br>';
echo $this->weight . '<br><br>';
}
}
$rd = '1 - Tyrion Lanister';
$bi = '2 - played by Peter Dinklage';
$fm = '3 - in "The Game of Thrones".';
$aa = '4 - Borned in June 11, 1969.';
$ht = '5 - He has the height 4.3307ft = 1.32m';
$wt = '6 - and the weight 110.231lbs = 50kg.';
$Dwarf = new Dwarf($rd, $bi, $fm, $aa, $ht, $wt);
$Dwarf->intro();
?>
<?php
final class Dwarfs {
public $name;
public $behavior;
public $friend;
public $age;
public function get_name()
{
return $this->name;
}
public function get_behavior()
{
return $this->behavior;
}
public function get_friend()
{
return $this->friend;
}
public function get_age()
{
return $this->age;
}
public function __construct($name, $behavior, $friend, $age)
{
$this->name = $name;
$this->behavior = $behavior;
$this->friend = $friend;
$this->age = $age;
}
public function intro()
{
echo $this->name . '<br><br>';
echo $this->behavior . '<br><br>';
echo $this->friend . '<br><br>';
echo $this->age . '<br><br>';
}
}
$nm = '1 - Happy.';
$bh = '2 - This dwarf is always cheerful and happy about everything.';
$fr = '3 - Snow White friend.';
$ag = '4 - 1937 - Year of the first performance of "Snow White and the Seven Dwarfs".';
$Dwarf_sw = new Dwarfs($nm, $bh, $fr, $ag);
echo $Dwarf_sw->get_name();
echo '<br><br>';
echo $Dwarf_sw->get_behavior();
echo '<br><br>';
echo $Dwarf_sw->get_friend();
echo '<br><br>';
echo $Dwarf_sw->get_age();
echo '<br><br><br>';
/* The class Dwarf is inherited from the class Dwarfs */
class Dwarf extends Dwarfs
{
public function message()
{
echo "A real famous dwarf:<br><br>";
}
}
$rd = '1 - Tyrion Lanister';
$bi = '2 - played by Peter Dinklage';
$fm = '3 - in "The Game of Thrones".';
$aa = '4 - Borned in June 11, 1969.';
$Dwarf = new Dwarf($rd, $bi, $fm, $aa);
$Dwarf->message();
$Dwarf->intro();
?>
<?php
final class Dwarfs {
public $name;
public $behavior;
public $friend;
public $age;
public function __construct($name, $behavior, $friend, $age)
{
$this->name = $name;
$this->behavior = $behavior;
$this->friend = $friend;
$this->age = $age;
}
public function intro()
{
echo $this->name . '<br><br>';
echo $this->behavior . '<br><br>';
echo $this->friend . '<br><br>';
echo $this->age . '<br><br>';
}
}
class Dwarf extends Dwarfs {
public $height;
public $weight;
public function __construct($name, $behavior, $friend, $age, $height, $weight)
{
$this->name = $name;
$this->behavior = $behavior;
$this->friend = $friend;
$this->age = $age;
$this->height = $height;
$this->weight = $weight;
}
public function intro()
{
echo $this->name . '<br><br>';
echo $this->behavior . '<br><br>';
echo $this->friend . '<br><br>';
echo $this->age . '<br><br>';
echo $this->height . '<br><br>';
echo $this->weight . '<br><br>';
}
}
$rd = '1 - Tyrion Lanister';
$bi = '2 - played by Peter Dinklage';
$fm = '3 - in "The Game of Thrones".';
$aa = '4 - Borned in June 11, 1969.';
$ht = '5 - He has the height 4.3307ft = 1.32m';
$wt = '6 - and the weight 110.231lbs = 50kg.';
$Dwarf = new Dwarf($rd, $bi, $fm, $aa, $ht, $wt);
$Dwarf->intro();
?>