Late Binding in C++ (Dynamic Binding)
C++ – Late Binding
Definition of Late Binding in C++(Dynamic Binding): Whenever the child class is not satisfied with the implementation of the parent class behavior then it can redefine that particular method with its own definition.Late Binding in C++
Late binding in C++(Dynamic Binding) is nothing but the most popular run polymorphic technique method overloading
- We call it as late binding because method calls or identified during the execution(runtime). Among multiple methods in overriding, the method call is binded(attached or matched) with the required method definition at runtime
- We call it as late because identification of method calls happen not at compilation but during the execution
C ++ program to demonstrate method overriding
#include <iostream> using namespace std; class parent //parent class { public: void property() { cout << "land+cash+gold\n"; } void marriage() { cout << "arranged marriage\n"; } }; class child:public parent //child class { public: void marriage() //own definition of child { cout << "love marriage\n"; } //contains property() from parent and its own marriage() }; int main() { child c; c.property(); c.marriage(); parent p; p.property(); p.marriage(); return 0; }
Output:
land+cash+gold love marriage land+cash+gold arranged marriage
- Here year child class inherits two methods from parent ,property() and marriage() child is satisfied with property() but not with marriage() .hence child class had given its own implementation for marriage()
- If the child class don’t inherit parent method he will not get the property().that’s why there will inheritance during overriding
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment