View Single Post
  #1 (permalink)  
Old March 23rd, 2020, 02:55 AM
ankitdixit ankitdixit is offline
Registered User
 
Join Date: Sep 2019
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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;
}
Reply With Quote