-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21-POO.php
61 lines (48 loc) · 1.45 KB
/
21-POO.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<html>
<!--Un objeto tiene propiedades(atributos): Color, Peso, Alto, Largo
tine un comportamiento (¿que es capaz de hacer?): Frenar, acelerar, aparcar
CLASE=modelo donde se redactan las caracteristicas comunes de un grupo de objetos
INSTANCIA= creacion de un objeto de la clase-->
<head>
<meta charset="utf-8">
<title>PROGRAMACION ORIENTADA A OBJETOS</title>
</head>
<body>
<?php
//clase
class Coche{
//propiedades
var $ruedas;
var $color;
var $motor;
function Coche(){//metodo constructor para el estado inicial
// con el $this hacemos referencia a la propia clase, como su pusiera coche
$this->ruedas=4;// con -> hacemos referencia al atributo
$this->motor=1600;
$this->color="";
}
function arrancar(){
echo "estoy arrancando<br>";
}
function girar(){
echo "estoy girando<br>";
}
function frenar(){
echo "estoy frenando<br";
}
function establece_color($color_coche){
$this->color=$color_coche;
echo"el color de " . $nombre_coche . "es" . $this->color . "<br>";
}
}
//objeto
$renault = new Coche();
$seat= new Coche();
$mazda = new Coche();
$mazda->girar();//llamada a la funcion
$renault->establece_color("Rojo","renault");
$mazda->establece_color("Azul","mazda");
echo $mazda-> ruedas;
?>
</body>
</html>