Program : constructor, destructor in multilevel inheritance


#include<iostream.h>
#include<conio.h>
class base
{
protected:
int a;
public:
base(int x)
{
a=x;
cout<<"Inside base constructor"<<endl;
}
~base()
{
cout<<"Inside base destructor"<<endl;
}
};//end of base class


class derived1 : public base
{
protected:
int b;
public:
derived1(int x,int y):base(x)
{
b=y;
cout<<"Inside derived1 constructor"<<endl;
}
~derived1()
{
cout<<"Inside derived1 destructor"<<endl;
}
};//end of derived class
class derived2 : public derived1
{
int c;
public:
derived2(int x,int y,int z):derived1(x,y)
{
c=z;
cout<<"Inside derived2 constructor"<<endl;
}
~derived2()
{
cout<<"Inside derived2 destructor"<<endl;
}
void show()
{
    cout<<"a : "<<a<<" "<<"b : "<<b<<"  "<<"c : "<<c<<endl;
}
};//end of derived class
void main()
{
clrscr();
derived2 obj(3,4,5);
obj.show();
}
/*
Inside base constructor
Inside derived1 constructor
Inside derived2 constructor
a : 3 b : 4  c : 5
Inside derived2 destructor
Inside derived1 destructor
Inside base destructor
*/

8 comments:

Anonymous said...

thank you.....helped a lot

Anonymous said...

This excellent website truly has all the information and facts I
needed concerning this subject and didn't know who to ask.

My site - cellulite treatment reviews

Anonymous said...

thanks a lot

Unknown said...

Very informative article.Thank you author for posting this kind of article .

http://www.wikitechy.com/view-article/insertion-sorting-

program-in-cpp-with-example-and-explanation



Both are really good,
Cheers,
Venkat

Unknown said...

Useful post about constructor and destructor in multiple inheritance..java training in chennai

Unknown said...

Very informative ..i suggest this blog to my friends..Thank you for sharingjava training in chennai | chennai's no.1 java training in chennai | best java institute in chennai

jefrin said...

It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.

Devops Course Training in Chennai |Best Devops Training Institute in Chennai
Selenium Course Training in Chennai |Best Selenium Training Institute in Chennai
Java Course Training in Chennai | Best Java Training Institute in Chennai

Unknown said...

browse around these guys replica bags toronto site link replica bags los angeles replica dolabuy replica bags paypal

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|