Advertisement
Guest User

Untitled

a guest
May 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2.  class Persona
  3.  { public $nombre;
  4.    public $identificacion;
  5.    // public $edad;
  6.    
  7.     function __construct($nombre, $id)
  8.     {
  9.         $this->nombre = $nombre;
  10.         $this->identificacion = $id;
  11.     }
  12.  
  13.     public function Mostrar()
  14.     {
  15.         $res = "Nombre : $this->nombre - Identificación : $this->identificacion";
  16.         return $res;
  17.     }
  18.  }
  19.  
  20.     class Estudiante extends Persona
  21.     {
  22.         public $nota1;
  23.         public $nota2;
  24.         public $nota3;
  25.  
  26.         function setNotas($n1,$n2,$n3)
  27.         {
  28.             $this->nota1 = $n1;
  29.             $this->nota2 = $n2;
  30.             $this->nota3 = $n3;
  31.         }
  32.  
  33.         public function Mostrar()
  34.         {   $per = parent::Mostrar();
  35.             $res = $per.'<br>';
  36.             $res .= "Nota1 : $this->nota1 / Nota2 : $this->nota2 / Nota3 : $this->nota3";
  37.             return $res;
  38.         }
  39.     }  
  40.  
  41. $est1 = new Estudiante("Carlos", '456');
  42. $est1->setNotas(3.2, 2.5, 2.2);
  43. echo $est1->Mostrar().'<br>';
  44.  
  45. // var_dump($est1);
  46.  
  47. /*
  48.  $per1 = new Persona("Pedro", "123");   // creando un objeto
  49.  $x = $per1->Mostrar();
  50.  echo $x;
  51.  */
  52.  
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement