- Crea una clase
Humano
que imprima su nombre y su edad - Crea tres objetos diferentes de la clase
Humano
- Crea una clase
Mexicano
que herede de la claseHumano
e imprima su nacionalidad - Crea tres objetos diferentes de la clase
Mexicano
Created
August 16, 2017 20:14
-
-
Save jorandradefig/24c888e581ff27bf5ded35e9c073ee24 to your computer and use it in GitHub Desktop.
puentejose
commented
Aug 18, 2017
class Humano{
private name: string;
private age: number;
constructor(name:string, age:number){
this.name=name;
this.age=age;
}
sayHello(){
console.log(`me llamo ${this.getName()} y tengo ${this.getAge()}`);
}
setName(name:string){
this.name=name;
}
getName(){
return this.name;
}
setAge(age:number){
this.age=age;
}
getAge(){
return this.age;
}
}
let a = new Humano('Ignacio', 21);
a.sayHello();
let cb = new Humano('Carlos', 31);
cb.sayHello();
let b = new Humano('Jacinto', 12);
b.sayHello();
class Mexicano extends Humano{
private nacionalidad: String;
private name:String;
private age:number;
constructor(name:string, age:number, nacionalidad:string){
super(name,age)
this.nacionalidad=nacionalidad;
this.name=name;
this.age=age;
}
sayHello(){
console.log(Mi nombre es ${this.getName()}, tengo ${this.getAge()} años y mi nacionalidad es ${this.nacionalidad}
);
}
}
let d = new Mexicano('Juan', 21, 'Mexicana' )
d.sayHello();
let e = new Mexicano('Jose', 18, 'Mexicana' )
e.sayHello();
let f = new Mexicano('Luis', 25, 'Mexicana' )
f.sayHello();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment