Explain Runtime Polymorphism and compile time
In : BCA Subject : OOPS and Data StructuresIn C++, polymorphism allows objects to behave differently even though they are accessed using the same function name.
There are two types of polymorphism in C++:
Compile Time Polymorphism
Runtime Polymorphism
- Compile Time Polymorphism
Also called Early Binding or Static Polymorphism
This type of polymorphism is resolved at compile time — meaning the compiler already knows which function will be called.
By using:
Function Overloading
Operator Overloading - Runtime Polymorphism
Also called Late Binding or Dynamic Polymorphism
This type of polymorphism is resolved at runtime — the actual object determines which function is called.
By using:
Virtual Functions
Base class pointer/reference to derived class object