What is inheritance in C++?| Simple program to understand inheritance |

Inheritance is part of object oriented programming system. In inheritance the logic work like this that if you running a software and you are getting update in your software. That’s fine everyone gets update but in every update you will see that after updating you will get extra feature with old one. Means you will get new with old one and it will never happens that you will lost facility which was earlier.And C++ has a different beauty to do that. Look at this program of c++ to understand this.

#include
#include
class A
{
public:A()
{
cout<<"Zero Parameter Constructor of A\n";
}
public: A(int a)
{
cout<<"One Parameter Constructor of A\n";
}
};
class B:A
{
public:B()
: A(0)
{
cout<<"Constructor of B\n";
}
};
void main()
{
clrscr();
B b1;
//A a1(0);
getch();
}

Run program and call the constructor one by one . You will see that when you will the above means A you will get print One Parameter Constructor of A and when you will call B you will get both print of A and B. That’s how the Inheritance work.

Leave a Reply