Advertisement
fueanta

AIUB SUMMER15-16 pl2 final quiz02 3rd Ques.

Sep 6th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Human {
  5.     int a;
  6. public:
  7.     Human(int a=0) : a(a) {}
  8.     virtual int getage()=0;
  9.     virtual void virtualFunction()=0;
  10. };
  11.  
  12. class Student : public Human {
  13.     int age;
  14. public:
  15.     Student(int age=0,int a=0) : Human(a) {this->age= age;}
  16.     int getage() {return age;}
  17.     void virtualFunction() {
  18.         age=25;
  19.         cout << age << endl;
  20.     }
  21. };
  22.  
  23. int main() {
  24.     Student st(10,20);
  25.     cout << "Age: " << st.getage() << endl;
  26.     Human *h;
  27.     h=&st;
  28.     cout << "Age: " << h->getage() << endl;
  29.     h->virtualFunction();
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement