class Mascota {
color: string;
tamanyo: string;
constructor(color: string, tamanyo: string) {
this.color = color;
this.tamanyo = tamanyo;
}
getColor() {
return this.color;
}
setColor(color: string) {
this.color=color;
}
getTamanyo() {
return this.tamanyo;
}
setTamanyo(tamanyo: string) {
this.tamanyo = tamanyo;
}
}
let mascota = new Mascota("café", "chico");
console.log('Mascota{color:'+mascota.getColor()+ ', tamanyo:'+mascota.getTamanyo()+'}');
Ejemplo de clase en TypeScript
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.