interface Electrico {
val bateria: Int
fun cargar()
fun nivelBateria(): Int
}
interface ConGPS {
fun obtenerUbicacion(): String
fun establecerDestino(destino: String)
}
info Cada interface define un comportamiento específico
class CocheElectrico(val modelo: String) : Electrico, ConGPS {
override var bateria = 0
private var ubicacion = "Desconocida"
private var destino = ""
override fun cargar() {
bateria = 100
println("⚡ $modelo cargado al 100%")
}
override fun nivelBateria() = bateria
override fun obtenerUbicacion() = ubicacion
override fun establecerDestino(dest: String) {
destino = dest
println("📍 Destino: $destino")
}
}
play_arrow Ejemplo de uso:
val tesla = CocheElectrico("Tesla Model 3")
tesla.cargar()
tesla.establecerDestino("Barcelona")