 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you the difference between static binding and dynamic binding in C++. Before starting, you can note my information. You can follow my YouTube channel that is Sanjay Gupta underscore tax school. You can download my Android app that is Techimus which is available on Google Play. Now coming on to the topic. For demonstration purpose I have implemented a code for you. Here header file IO stream is included. Then STD namespace is used. Then first class is A which is having an attribute X. Inside public section I have implemented first function that is void read. It will display a message enter a value on console and the entered value will be stored inside X. Then show method is implemented which will display value of X on console. Then A class is narrated into class B. So class A is base class and class B is treated as derived class here. And after that main function is implemented. In class B you can see an attribute Y is declared. Then I have implemented read function which will display message enter a value on console. The entered value will be stored inside Y and that value is received through scene. Then show method is defined which will display a message on console and it will display value of Y on console. So this is the termination of class B. So class A members are available in class B and in main function pointer of class A is created that is P1 and you can see P1 equals to new B object is created. So P1 is of base class pointer. So the comments is saying pointer is of class A that is P1 and object of class B is created. So object is of class B is available. So here object is belonging to class B and pointer belongs to class A and then read and show functions are called through P1. So now we have to understand the binding here. Here P1 is calling read and show functions. So P1 belongs to A class. So in case of compilation time read and show functions of base class will be linked with this P1 because P1 belongs to A class. When we execute this program then read and show function of base class will be executed because right now virtual keyword is not used. So I am first executing this code so that you can understand the output. I am entering a value that is 3 and it is printing X equals to 3. You can see that X equals to and value of X is displayed through show function of class A. It means this read and show functions are executed for base class. So this is static binding. Static binding means at the compilation time read and show functions are linked for base class and those base class functions are executed at runtime. So static binding is worked at runtime so that is why it is known as static binding concept. Now what is the meaning of dynamic binding? Dynamic binding says that if at the time of compilation some functions are linked with the function calling statement and if at execution time those functions will be changed then that process is known as dynamic binding. So now you can see I have created object of class B which is pointed by pointer of class A but I want class B function should be executed. So for that purpose you have to use a spatial keyword that is virtual keyword. So here you can see I have created these two functions as virtual function now. So class A that is base class its functions are now virtual functions. So virtual function has a property that if compilation time some set of functions are linked with a pointer then at execution time virtual keyword checks which class address is available in the pointer. So here you can see pointer is receiving address of B class that is derived class. So virtual function transfers control from base class to the respective derived class. In our example the derived class is B. So read and show functions of B class will be executed now. You can see it by execution. It is asking for a value. I am entering 4. You can see here this time it is showing y equals to 4. Previously it was showing x equals to 4. So this time derived class read and show functions are executed because base class functions are now virtual functions. So this concept is known as dynamic binding. At compilation time functions of base class are linked but at execution time functions of derived classes are executed and this all is done with the help of virtual function or virtual keyword. So friends if you are not using virtual keyword then the pointer type is used preferably but if you are using virtual keyword or virtual function then the address which is stored inside the function is used preferably. So this is the difference between static binding and dynamic binding. I am summarizing it now. Static in case of static binding the compilation time function call and execution time function execution both are same but in case of dynamic binding the compilation time function call and execution time function execution both are different. In case of dynamic binding linking is done with base class but execution is done with derived class functions. So this is all about static and dynamic binding in C++. I hope you have understood the concept. If you want to watch more programming related videos you can follow my YouTube channel that is sanjaygupta underscore tech school. Thank you for watching this video.