C++ Program to illustrates the use of Constructors in multilevel inheritance
belongs to collection: C++ Constructor and Destructor Solved Programs
All Answers
total answers (1)
belongs to collection: C++ Constructor and Destructor Solved Programs
total answers (1)
What are Constructors in C++?
A class constructor is a special member function of a class that is executed whenever we create new objects of that class.
The Compiler calls the Constructor whenever an object is created. Constructors iitialize values to object members after storage is allocated to the object.
While defining a contructor you must remeber that the name of constructor will be same as the name of the class, and contructors never have return type.
Constructors can be defined either inside the class definition or outside class definition using class name and scope resolution :: operator.
Below is the source code for C++ Program to illustrates the use of Constructors in multilevel inheritance which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
OUTPUT : :
/* C++ Program to illustrates the use of Constructors in multilevel inheritance */ The first object is in use now******** Constructor of class A without any argument is invoked Constructor of class B without any argument is invoked Constructor of class C without any argument is invoked Enter the value of x: 2 Enter the value of y: 3 Enter the value of z: 4 x = 2 y = 3 z = 4 The second object is in use now******** Constructor of class A with one argument is invoked Constructor of class B with two arguments in invoked Constructor of class C with three arguments is invoked x = 5 y = 6 z = 7 Process returned 0Above is the source code and output for C++ Program to illustrates the use of Constructors in multilevel inheritance which is successfully compiled and run on Windows System to produce desired output.
need an explanation for this answer? contact us directly to get an explanation for this answer