Está en la página 1de 2

----------------------------------------------

Clase Padre Constructor


----------------------------------------------
<?php
class Operacion{
public $cantidadUno =0;
public $cantidadDos=0;
public $resultado =0;

function __construct($intcantidad1, $intcantidad2){ /** Se Reciben los datos


del constructor **/

$this->cantidadUno = $intcantidad1;
$this->cantidadDos = $intcantidad2;

}
function getSuma(){
$this->resultado = $this->cantidadUno+ $this->cantidadDos;
return $this->resultado;
}

function getResta(){
$this->resultado = $this->cantidadUno - $this->cantidadDos;
return $this->resultado;
}
function getMulti(){
$this->resultado = $this->cantidadUno * $this->cantidadDos;
return $this->resultado;
}

?>

----------------------------------------------
Clase Hijo
----------------------------------------------
<?php

require_once ("ClassOperacion.php");

$Operacion = new Operacion(20,5); /** Se envia los datos al constructor **/

$totalSuma= $Operacion->getSuma();
echo "Total Suma:".$totalSuma;
echo "<br>";

$totalResta = $Operacion->getResta();
echo "Total Resta:".$totalResta;
echo "Aprendiendo Pool Orientada a Objetos ";
echo "<br>";

$totalMulti = $Operacion->getMulti();

echo "Total multi:".$totalMulti;


?>

También podría gustarte