La descarga está en progreso. Por favor, espere

La descarga está en progreso. Por favor, espere

UNIVERSIDAD DIEGO PORTALES Facultad de Ingeniería Programación Avanzada HERENCIA Tema: HERENCIA Ing. Javier Chamorro Cerón.

Presentaciones similares


Presentación del tema: "UNIVERSIDAD DIEGO PORTALES Facultad de Ingeniería Programación Avanzada HERENCIA Tema: HERENCIA Ing. Javier Chamorro Cerón."— Transcripción de la presentación:

1 UNIVERSIDAD DIEGO PORTALES Facultad de Ingeniería Programación Avanzada HERENCIA Tema: HERENCIA Ing. Javier Chamorro Cerón

2 HERENCIA La herencia es específica de la programación orientada a objetos, donde una clase nueva se crea a partir de una clase existente. La herencia (a la que habitualmente se denomina subclases) proviene del hecho de que la subclase (la nueva clase creada) contiene las atributos y métodos de la clase primaria.

3

4 #include using namespace std; class animal{ private: int edad; int numpatas; public: animal(){} animal(int edad, int numpatas){ this->edad = edad; this->numpatas = numpatas; } int getEdad(){ return this->edad; } void setEdad(int edad){ this->edad = edad; } int getNumpatas(){ return this->numpatas; } void setNumpatas(int np){ this->numpatas = np; } };

5 class felino : public animal{ private: string nombre; public: felino(){} felino(string nombre){ this->nombre = nombre; } string getNombre(){ return this->nombre; } void setNombre(string nom){ this->nombre = nom; } };

6 class canino : public animal{ private: string nombre; string dueno; public: canino(){} canino(string nombre, string dueno){ this->nombre = nombre; this->dueno = dueno; } string getNombre(){ return this->nombre; } void setNombre(string nombre){ this->nombre = nombre; } string getDueno(){ return this->dueno; } void setDueno(string dueno){ this->dueno = dueno; } };

7 int main(int argc, char *argv[]) { felino *prim = new felino(); canino *segu = new canino(); prim->setEdad(10); prim->setNumpatas(4); prim->setNombre("MININO"); segu->setEdad(3); segu->setNumpatas(4); segu->setNombre("OBAMA"); segu->setDueno("CAPITAL"); cout getNombre()<<endl; cout getEdad()<<endl; cout getNumpatas()<<endl; cout<<endl; cout getNombre()<<endl; cout getEdad()<<endl; cout getNumpatas()<<endl; cout getDueno()<<endl; }

8


Descargar ppt "UNIVERSIDAD DIEGO PORTALES Facultad de Ingeniería Programación Avanzada HERENCIA Tema: HERENCIA Ing. Javier Chamorro Cerón."

Presentaciones similares


Anuncios Google