$this->nombre = $nom; } public function imprimir() { echo $this->nombre; echo '<br>'; } } $per1 = new Persona(); $per1->inicializar('Juan'); $per1->imprimir(); ?> <?php $per2 = new Persona(); $per2->inicializar('ana'); $per2->imprimir(); class Menu { private $enlaces = array(); private $titulos = array(); public function cargarOpcion($en, $tit) { $this->enlaces[] = $en; $this->titulos[] = $tit; } public function mostrar() { for ($f = 0; $f < count($this->enlaces); $f++) { echo '<a href="' . $this->enlaces[$f] . '">' . $this->titulos[$f] . '</a>'; echo "-"; }
public function imprimir() { parent::imprimir(); echo "Sueldo: {$this->sueldo}<br />"; }
<?php /** * */ class Persona { private $nombre; public function inicializar($nom) { $this->nombre = $nombre; } public function imprimir() { echo $this->nombre; echo "<br />"; } } //Anem a gastar la clase $per1 = new Persona(); $per1->inicializar("Lucia"); $per1->imprimir();
$this->edad = $edad; } public function imprimir() { echo "Nombre: {$this->nombre} Edad: {$this->edad}"; } } final class Empleado extends Persona { private $sueldo; public function cargarSueldo($sueldo) { $this->sueldo = $sueldo; } public function imprimirSueldo() { echo "Sueldo: {$this->sueldo}"; } } $emp1 = new Empleado(); $emp1->cargarDatos("Edgar", 26); echo "<br />"; $emp1->cargarSueldo(2000); $emp1->imprimir(); echo "<br />"; $emp1->imprimirSueldo(); echo "<br /><br />"; $pers = new Persona(); $pers->cargarDatos("David", 25); $pers->imprimir();