Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 12, 2019 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/722da692a95fce3bc635d4da6eb29d01 to your computer and use it in GitHub Desktop.
Save parzibyte/722da692a95fce3bc635d4da6eb29d01 to your computer and use it in GitHub Desktop.
/**
* 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