Thursday, 9 April 2015

Constructors in Multilevel Inheritance



Sample Program


#include <iostream.h>
class base
{
int rno;
char *name
public:
base(int no, char *n)
{
rno = no;
strcpy(name,n);
}
void showbase(void)
{
cout<<rno<<name<<endl;
}
};
class deri1:public base
{
int m1, m2;
public:
deri(int j, int k, int l, char *n):base(l,n)
{
m1 = j;
m2 = k;
}
void showderi1(void)
{
cout<<”derived1 values are”;
cout<<m1<<m2<<endl;
}
};
class deri2:public deri1
{
int tot;
public:
deri2(int i, int j, int k, int l, char *n):deri1(j,k,l,n)
{
tot = i;
}
void showderi2(void)
{
cout<<”derived2 values are”;
cout<<tot
}
};
void main()
{
deri D(100,50,50,101,”DKam”);
D.showbase();
D.showderi1();
D.showderi2();
}

No comments:

Post a Comment