Created with <3 with dartpad.dev.
Created
October 26, 2023 03:03
-
-
Save leonus96/a17254757fbc1e6a847beee1eee65842 to your computer and use it in GitHub Desktop.
POO: Herencia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Mascota { | |
| String nombre; | |
| String color; | |
| int edad; | |
| bool sexo; | |
| Mascota({ | |
| required this.nombre, | |
| required this.color, | |
| required this.edad, | |
| required this.sexo, | |
| }); | |
| void caminar() { | |
| print('Estoy caminando...'); | |
| } | |
| void comer() { | |
| print('Estoy comiendo...'); | |
| } | |
| void jugar() { | |
| print('Estoy jugando... '); | |
| } | |
| } | |
| class Gato extends Mascota { | |
| String tamanioCajaArena; | |
| Gato({ | |
| required super.nombre, | |
| required super.color, | |
| required super.edad, | |
| required super.sexo, | |
| required this.tamanioCajaArena, | |
| }); | |
| void trepar() { | |
| print('Estoy trepando'); | |
| } | |
| void maullar() { | |
| print('Miuaauuuuu...'); | |
| } | |
| void ronronear() { | |
| print('Rrrrr rrrr...'); | |
| } | |
| void acicalarse() { | |
| print('Me estoy acicalando...'); | |
| } | |
| } | |
| class Perro extends Mascota { | |
| String raza; | |
| String tallaCorrea; | |
| Perro({ | |
| required super.nombre, | |
| required super.color, | |
| required super.edad, | |
| required super.sexo, | |
| required this.raza, | |
| required this.tallaCorrea, | |
| }); | |
| void ladra() { | |
| print('Guau! guau!'); | |
| } | |
| void acicalar() { | |
| print('Me estan acicalando...'); | |
| } | |
| } | |
| void main() { | |
| final Perro perro = Perro( | |
| nombre: 'Aegon', | |
| color: 'gris', | |
| edad: 7, | |
| sexo: true, | |
| raza: 'Schnauzer', | |
| tallaCorrea: 'M' | |
| ); | |
| final Gato gato = Gato( | |
| nombre: 'Gatubela', | |
| color: 'marron', | |
| edad: 4, | |
| sexo: false, | |
| tamanioCajaArena: 'Grande', | |
| ); | |
| print('Nombre del perro: ${perro.nombre}'); | |
| perro.ladra(); | |
| perro.acicalar(); | |
| perro.comer(); | |
| perro.jugar(); | |
| perro.caminar(); | |
| print(''); | |
| print('Nombre del gato: ${gato.nombre}'); | |
| gato.maullar(); | |
| gato.ronronear(); | |
| gato.acicalarse(); | |
| gato.comer(); | |
| gato.jugar(); | |
| gato.caminar(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment