Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Human {
- int a;
- public:
- Human(int a=0) : a(a) {}
- virtual int getage()=0;
- virtual void virtualFunction()=0;
- };
- class Student : public Human {
- int age;
- public:
- Student(int age=0,int a=0) : Human(a) {this->age= age;}
- int getage() {return age;}
- void virtualFunction() {
- age=25;
- cout << age << endl;
- }
- };
- int main() {
- Student st(10,20);
- cout << "Age: " << st.getage() << endl;
- Human *h;
- h=&st;
- cout << "Age: " << h->getage() << endl;
- h->virtualFunction();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement