Q.2) a) What is a dynamic constructor? Explain with suitable example.
Ans.Dynamic constructor is used to allocate the memory to the objects at the run time.Memory is allocated at run time with the help of 'new' operator.
By using this constructor, we can dynamically initialize the objects.
Output:The value of obj1's ptr is:100
The value of obj2's ptr is: 90
b) What is function overloading? Explain with suitable example.
Ans.There are two types of polymorphism in C++. Compile time polymorphism and runtime polymorphism. Function overloading comes under the Compile time polymorphism. Function overloading is a process in which functions have same name but either the number of arguments or the data type of arguments has to be different. It does not depend upon the return type of functions because function will return a value when it is called.
Output:Sum of two integers :: 30
Sum of three double variable :: 60.6