// CLASSE BASE OU SUPERCLASSE
class Animal{
constructor(protected nome: string){
}
getNome(): string{
return this.nome;
}
//método
comer(){
console.log(`${this.nome} está comendo.`);
}
}
// CLASSE DERIVADA ou FILHA
class Cachorro extends Animal{
constructor(nome: string){
super(nome); // chamada ao construtor da superclasse
}
// método
latir(){
console.log(`${this.nome} está latindo.`);
}
}
// INICIALIZANDO OS OBJETOS
let rex = new Cachorro("Rex");
console.log(rex.getNome());
rex.comer();
rex.latir();
To embed this project on your website, copy the following code and paste it into your website's HTML: