Created
February 10, 2012 21:18
-
-
Save felladrin/1792957 to your computer and use it in GitHub Desktop.
Herança simples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Animal | |
{ | |
public: | |
Animal() {} | |
void respirar() | |
{ | |
cout << "respirei"; | |
} | |
void comer() | |
{ | |
cout << "comi"; | |
} | |
void reproduzir() | |
{ | |
cout << "reproduzi"; | |
} | |
}; | |
class Gato : public Animal | |
{ | |
public: | |
Gato() : Animal() {} | |
void respirar() | |
{ | |
cout << "ronronei"; | |
} | |
}; | |
int main() | |
{ | |
Animal a; | |
Gato g; | |
cout << "Animal.respirar(): "; | |
a.respirar(); | |
cout << endl << "Animal.comer(): "; | |
a.comer(); | |
cout << endl << "Animal.reproduzir(): "; | |
a.reproduzir(); | |
cout << endl << "Gato.respirar(): "; | |
g.respirar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment