Created
August 12, 2019 17:38
-
-
Save parzibyte/722da692a95fce3bc635d4da6eb29d01 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Clase en Kotlin | |
* | |
* @author parzibyte | |
* @link https://parzibyte.me/blog | |
* | |
* */ | |
class Mascota { | |
var nombre: String | |
get() { | |
println("Llamada al getter de nombre") | |
return field | |
} | |
set(nuevoNombre) { | |
println("Llamada al setter de nombre") | |
field = nuevoNombre | |
} | |
// Para edad, dejamos el setter y getter implícito | |
var edad: Int | |
constructor(nombre: String, edad: Int) { | |
this.nombre = nombre | |
this.edad = edad | |
} | |
fun saludar() { | |
println("¡Hola! me llamo $nombre y tengo $edad años. Woof") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment