What are the different forms of polymorphism??
Answer Posted / amit
There are two types of polymorphism:-
1.Compile time polymorphism
This is achieved by:
- Function overloading
- Operator overloading
2.Run time polymorphism
This is achieved through inheritance and virtual functions.
In this, base class has one or more virtual functions which
are overridden in the derived class. And then base class
pointer is used to access base or derived class virtual
function.
Example:-
class base {
public:
virtual void func() {
cout << "In base class" << endl;
}
};
class derived {
public:
void func() {
cout << "In derived class" << endl;
}
};
int main(){
base *bp, b;
derived d;
bp = &b;
bp->func(); // base class func() will be called
bp = &d;
bp->func(); // derived class func() will be called
return 0;
}
Here, the decision to call base or derived class func() is
taken at run time.
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Can main method override?
What are classes oop?
What does oop mean in snapchat?
How is class defined?
What is a class and object?
What is the benefit of oop?
what are the realtime excercises in C++?
What is the full form of oops?
What is data binding in oops?
i got a backdoor offer in process global,Bangalore..Can i work with it?
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?
What is difference between multiple inheritance and multilevel inheritance?
Will I be able to get a picture in D drive to the c++ program? If so, help me out?
What is an example of genetic polymorphism?
What is pure oop?