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
Is abstract thinking intelligence?
What is a superclass in oop?
What is and I oop mean?
What is solid in oops?
What is encapsulation oop?
What do you mean by overloading?
What is polymorphism programming?
if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?
How is polymorphism achieved?
What is static modifier?
Which is better struts or spring?
Can you inherit a private class?
what is difference between class template and template class?
What is overriding vs overloading?
Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.