Skip to content

Instantly share code, notes, and snippets.

@m1irka
Last active January 8, 2026 12:54
Show Gist options
  • Select an option

  • Save m1irka/0ba958b91bf91ef3d30826bad2bde9e4 to your computer and use it in GitHub Desktop.

Select an option

Save m1irka/0ba958b91bf91ef3d30826bad2bde9e4 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class Pet {
protected:
const char* name;
const char* ch;
public:
Pet(const char* n, const char* c) : name(n), ch(c) {}
void showInfo() {
cout << "Name: " << name << " Characteristic: " << ch << endl;
}
};
class Dog : public Pet {
public:
Dog(const char* n, const char* c) : Pet(n, c) {}
void showInfo() {
cout << "Dog Name: " << name << " Characteristic: " << ch << endl;
}
};
class Cat : public Pet {
public:
Cat(const char* n, const char* c) : Pet(n, c) {}
void showInfo() {
cout << "Cat Name: " << name << " Characteristic: " << ch << endl;
}
};
class Parrot : public Pet {
public:
Parrot(const char* n, const char* c) : Pet(n, c) {}
void showInfo() {
cout << "Parrot Name: " << name << " Characteristic: " << ch << endl;
}
};
int main() {
Dog d("Buddy", "Loyal and playful");
Cat c("Murka", "Independent and curious");
Parrot p("Kesha", "Talkative and colorful");
d.showInfo();
c.showInfo();
p.showInfo();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment