Runtime Polymorphism in C++
Hello Everyone, I am confused about the concept of Runtime Polymorphism in C++. I have faced one interview and the interviewer asked me this question where I was not given the answer. I have checked in google with code example but I didn't get it. Can anyone know about it and suggest me some more questions which are very useful to me for my upcoming interviews? I have added one code example of runtime polymorphism, is it right?
#include
using namespace std;
class Base {
public:
virtual void show() { cout<<" In Base \n"; }
};
class Derived: public Base {
public:
void show() { cout<<"In Derived \n"; }
};
int main(void) {
Base *bp = new Derived;
bp->show(); // <- Runtime Polymorphism in Action
return 0;
}
|