Skip to content

Instantly share code, notes, and snippets.

@jorandradefig
Created August 16, 2017 20:14
Show Gist options
  • Save jorandradefig/24c888e581ff27bf5ded35e9c073ee24 to your computer and use it in GitHub Desktop.
Save jorandradefig/24c888e581ff27bf5ded35e9c073ee24 to your computer and use it in GitHub Desktop.
  1. Crea una clase Humano que imprima su nombre y su edad
  2. Crea tres objetos diferentes de la clase Humano
  3. Crea una clase Mexicano que herede de la clase Humano e imprima su nacionalidad
  4. Crea tres objetos diferentes de la clase Mexicano
@naxido96
Copy link

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