- 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.
Crea tres objetos diferentes de la clase Humano
Crea una clase Mexicano que herede de la clase Humano e imprima su nacionalidad
Crea tres objetos diferentes de la clase Mexicano */
class Humano {
//Propiedades
private name : string;
private age : number;
//Constructor
constructor(name : string, age : number){
console.log("Humano creado...");
this.name = name;
this.age = age;
}
//Métodos
soyHumano(){
console.log(`Me llamo ${this.name} y tengo ${this.age}, juro que soy un humano totalmente normal con órganos humanos normales`)
}
}
let humano1 = new Humano("Clark Kent", 41);
let humano2 = new Humano("Zim", 21);
let humano3 = new Humano("Hillary", 123);
humano1.soyHumano();
humano2.soyHumano();
humano3.soyHumano();
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._age = _age;
this._name = _name;
}
soyDe(){
console.log(`Me llamo ${this._name} y tengo ${this._age} y soy del planeta tierra, específicamente de ${this._nacionalidad}`)
}
}
let mexa1 = new Mexicano("José",28,"mexicano");
let mexa2 = new Mexicano("Abril", 26, "México");
let mexa3 = new Mexicano("Erika", 28, "San Diego");
mexa1.soyDe();
mexa2.soyDe();
mexa3.soyDe();
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
class Humano {
private _nombre: string;
private _edad: number;
constructor(nombre: string, edad: number){
console.log(
${nombre},${edad}
);this._nombre = nombre;
this._edad = edad;
}
}
let a = new Humano("Paola", 25);
let b = new Humano("Luis", 28);
let c = new Humano("Yesi", 21);
class Mexicano extends Humano {
private _nacionalidad: string;
}
let d = new Mexicano("Carolina", 36, "Colombiana");
let e = new Mexicano("Roberto", 54, "Brasileño");
let f = new Mexicano("Marcela", 70, "Cubana");