Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
POO Sobrecarga de métodos en Android Studio [58]
Video: https://youtu.be/3VOMl7-pv2A
- Loading branch information
1 parent
7e785e0
commit 9c765e2
Showing
2 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Crear una clase llamada Vehículo. | ||
Crear tres atributos marca, modelo y sku | ||
Crear dos métodos constructores uno con marca y modelo y otro solo con sku. | ||
Crear dos instancias de vehiculo uno se instancia con marca y modelo y el otro solo con sku. | ||
Crear dos métodos sobrecargados llamados acelerar que reciban uno y ningun parametro y que cada uno muestre su parámetro si es que tiene. | ||
*/ | ||
package com.programadornovato.myapplication | ||
|
||
class Vehiculo { | ||
var marca:String?=null | ||
var modelo:String?=null | ||
var sku:String?=null | ||
constructor(_marca:String,_modelo:String){ | ||
marca=_marca | ||
modelo=_modelo | ||
} | ||
constructor(_sku:String){ | ||
sku=_sku | ||
} | ||
fun acelerar(){ | ||
if(marca!=null){ | ||
println("El vehiculo $marca $modelo esta acelerando") | ||
}else{ | ||
println("El vehiculo $sku esta acelerando") | ||
} | ||
} | ||
fun acelerar(km:Int){ | ||
if(marca!=null) { | ||
println("El vehiculo $marca $modelo esta acelerando a $km Km/h") | ||
}else{ | ||
println("El vehiculo $sku esta acelerando a $km Km/h") | ||
} | ||
} | ||
} |