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
What is a null tree?
What does I oop mean?
#include
What is the main feature of oop?
What are the 3 principles of oop?
Is html an oop?
What is data binding in oops?
what is the 3 types of system development life cycle
Can we override main method?
What is a class and object?
write knight tour problem which is present in datastructure
Why do we use oop?
write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.
What is object and example?
What are oops methods?