05/01_dedicnost.php


  1  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
  2  <html>
  3  <head>
  4    <meta http-equiv="Author" content="Imrich BURANSKY" />
  5    <meta http-equiv="Content-Type" content="text/html; charset=Windows-1250" />
  6    <title>Dedičnosť</title>
  7  </head>
  8  <body>
  9  <div>
 10  <h2>Dedičnosť</h2>
 11  <?php
 12  
 13  class CA
 14  {
 15    public function __construct()
 16    {
 17      echo "CA: Konštruktor<br />\n";
 18    }
 19  
 20    public function FA ()
 21    {
 22      echo "CA: Funkcia FA<br />\n";
 23    }
 24  }
 25  
 26  class CB extends CA
 27  {
 28    public function __construct()
 29    {
 30      echo "CB: Konštruktor<br />\n";
 31    }
 32  
 33    public function FB ()
 34    {
 35      echo "CB: Funkcia FB<br />\n";
 36    }
 37  
 38    public function FX ()
 39    {
 40      echo "CB: Funkcia FX<br />\n";
 41      parent::FA();
 42    }
 43  }
 44  echo "<b>Vytvorenie a použitie objektu triedy CA</b><br />\n";
 45  $A = new CA(); // CA: Konštruktor
 46  $A->FA();      // CA: Funkcia FA
 47  echo "<b>Vytvorenie a použitie objektu triedy CB</b><br />\n";
 48  $B = new CB(); // CB: Konštruktor
 49  $B->FB();      // CB: Funkcia FB
 50  $B->FA();      // CA: Funkcia FA
 51  $B->FX();      // CB: Funkcia FX
 52                 // CA: Funkcia FA
 53  ?>
 54  </div>
 55  </body>
 56  </html>

« Späť