C++ Program to illustrates the use of Constructors in Single 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 Single 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 single inheritance */ The first object b1 is in use******** The constructor of the class A without any argument is invoked*** The constructor of the class B without any argument is invoked** Enter the value of x: 1 Enter the value of y: 2 x = 1 y = 2 The second object b2 is in use******** The constructor of the class A with one argument is invoked*** The constructor of the class B with two arguments is invoked*** x = 5 y = 6 Process returned 0Above is the source code and output for C++ Program for use of Constructors in single 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