<?php
class Coche{
var $ruedas;
var $color;
var $motor;
function Coche(){
$this->ruedas = 4;
$this->color = "";
$this->motor = 1600;
}
function arrancar(){
echo "Estoy arrancando<br>";
}
function girar(){
echo "Estoy girando<br>";
}
function frenar(){
echo "Estoy frenando<br>";
}
function establece_color($color_coche, $nombre_coche){
$this->color=$color_coche;
echo "El color de ".$nombre_coche." es: ".$this->color."<br>";
}
}
//-------------------------------------------------------------------------
class Camion{
var $ruedas;
var $color;
var $motor;
function Camion(){
$this->ruedas = 8;
$this->color = "gris";
$this->motor = 2600;
}
function arrancar(){
echo "Estoy arrancando<br>";
}
function girar(){
echo "Estoy girando<br>";
}
function frenar(){
echo "Estoy frenando<br>";
}
}
?>
class Coche{
var $ruedas;
var $color;
var $motor;
function Coche(){
$this->ruedas = 4;
$this->color = "";
$this->motor = 1600;
}
function arrancar(){
echo "Estoy arrancando<br>";
}
function girar(){
echo "Estoy girando<br>";
}
function frenar(){
echo "Estoy frenando<br>";
}
function establece_color($color_coche, $nombre_coche){
$this->color=$color_coche;
echo "El color de ".$nombre_coche." es: ".$this->color."<br>";
}
}
//-------------------------------------------------------------------------
class Camion{
var $ruedas;
var $color;
var $motor;
function Camion(){
$this->ruedas = 8;
$this->color = "gris";
$this->motor = 2600;
}
function arrancar(){
echo "Estoy arrancando<br>";
}
function girar(){
echo "Estoy girando<br>";
}
function frenar(){
echo "Estoy frenando<br>";
}
}
?>
Archivo para abrir en el navegador
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP OO_02</title>
</head>
<body>
<?php
include ("24_vehiculos.php");
$mazda = new Coche();
$pegaso = new Camion();
echo "El Mazda tiene " . $mazda->ruedas . " ruedas<br>";
echo "El Pegaso tiene " . $pegaso->ruedas . " ruedas";
?>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>PHP OO_02</title>
</head>
<body>
<?php
include ("24_vehiculos.php");
$mazda = new Coche();
$pegaso = new Camion();
echo "El Mazda tiene " . $mazda->ruedas . " ruedas<br>";
echo "El Pegaso tiene " . $pegaso->ruedas . " ruedas";
?>
</body>
</html>