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 html an oop?
Which type does string inherit from?
can inline function declare in private part of class?
write a C++ program for booking using constructor and destructor.
What is polymorphism explain?
What is inheritance in simple words?
i am getting an of the type can not convert int to int *. to overcome this problem what we should do?
What is pure oop?
I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...
Why is object oriented programming so hard?
What is the point of oop?
What does enum stand for?
Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.
• What are the desirable attributes for memory managment?
What is the difference between encapsulation and polymorphism?