Polymorphism In C++ Geeksforgeeks Code Example


Example: polymorphism-program.cpp

#include <iostream>  using namespace std;  class Person{ public:     virtual void introduce(){     cout <<"hey from person"<<endl;     } };  class Student : public Person{ public:     void introduce(){     cout <<"hey from student"<<endl;     } };  class Farmer : public Person{ public:     void introduce(){     cout <<"hey from Farmer"<<endl;     } };  void whosThis(Person &p){ p.introduce(); }  int main() {     Farmer anil;     Student alex;      whosThis(anil);     whosThis(alex);     return 0; }

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable