Created
October 28, 2012 18:09
-
-
Save bfb/3969329 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
// classe Carro com os parâmetros separados por "," e seus tipos separados por ":" | |
class Carro(var valor: Float = 0, modelo: String, ano: Int){ | |
// definição do método a partir do operador "=" inline | |
def detalhes = printf("CARRO: " + modelo + "\nANO: " + ano + "\nVALOR: " + valor) | |
// tipo de retorno do método declarado no final da assinatura | |
def alterarValor(valor: Float): Float = { | |
this.valor = valor | |
return this.valor | |
} | |
} | |
// parâmetros nomeados | |
var carro = new Carro(modelo = "Gol", ano = 2011) | |
// os parênteses são opcionais para métodos sem argumentos | |
carro.alterarValor(29000) | |
carro.detalhes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment