In this, we are going to see a Basic program for Single Inheritance with constructors in C++ Programming Language.
The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <conio.h>
class ParentClass
{
public:
ParentClass()
{
cout << "Constructor of Parent-Class\n";
}
};
class ChildClass : public ParentClass
{
public:
ChildClass()
{
cout << "Constructor of Child-Class";
}
};
void main()
{
clrscr();
ChildClass obj;
getch();
}
//...........Coded by Shreya Idate
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class ParentClass
{
public:
ParentClass()
{
cout << "Constructor of Parent-Class\n";
}
};
class ChildClass : public ParentClass
{
public:
ChildClass()
{
cout << "Constructor of Child-Class";
}
};
int main()
{
ChildClass obj;
return 0;
}
//...........Coded by Shreya Idate
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP