Page 194 - DCAP404 _Object Oriented Programming
P. 194
Unit 9: Inheritance
virtual COLOR GetColor() const { return itsColor; } Notes
protected:
HANDS itsHeight;
COLOR itsColor;
};
Horse::Horse(COLOR color, HANDS height, int age):
Animal(age),
itsColor(color),itsHeight(height)
{
cout << "Horse constructor...\n";
}
class Bird : public Animal
{
public:
Bird(COLOR color, bool migrates, int age);
virtual ~Bird() {cout << "Bird destructor...\n"; }
virtual void Chirp()const { cout << "Chirp... "; }
virtual void Fly()const{ cout << "fly! "; }
virtual COLOR GetColor()const { return itsColor; }
virtual bool GetMigration() const { return itsMigration; }
protected:
COLOR itsColor;
bool itsMigration;
};
Bird::Bird(COLOR color, bool migrates, int age):
Animal(age),
itsColor(color), itsMigration(migrates)
{
cout << "Bird constructor...\n";
}
class Pegasus : public Horse, public Bird
{
LOVELY PROFESSIONAL UNIVERSITY 187