Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Aula 1 - Orientacao a Objetos - Mao na Massa
//Kotlin 1.1 fun main(args: Array<String>) { var pessoas: List<Pessoa?> = listOf( Aluno("Nicholas", null, 17, Boletim()), null, Professor("Guilherme", 37, "Matematica"), Pessoa("Natan", 23) ) for (pessoa in pessoas) { pessoa?.let { println("${it.nome} tem ${it.idade} anos.") if (it is Aluno) { println("Matricula ${it.numMatricula ?: "não existe"}") } if (it is Professor) { println("Da aula de ${it.nomeMateria}") it.ensinar(pessoas.first() as Aluno) } it.comer() } } } open class Pessoa(var nome: String, var idade: Int) { fun comer() { println("${nome} está comendo") } } class Professor( nome: String, idade: Int, var nomeMateria: String): Pessoa(nome, idade) { fun ensinar(aluno: Aluno) { println("${nome} está dando aula de ${nomeMateria} para ${aluno.nome}") //codigo de aula } } class Aluno( nome: String, var numMatricula: String?, idade: Int, var boletim: Boletim): Pessoa(nome, idade) { } class Boletim { var notas: List<Float> = listOf() }
run
|
edit
|
history
|
help
0
Fibonacci in Kotlin
Rotate array
Kotlin
degerliilkornek
Arun1
KotlineMerg
test.java
Haha
Kotlin
D