PROGRAM FOR SINGLE INHERITANCE USING PRIVATE
//program for single inheritance using private
#include<iostream.h>
#include<conio.h>
class b
{
int a;
public:
int b;
void getab()
{
a=5;
b=10;
}
void showa()
{
cout<<"a="<<a<<endl;
}
int geta()
{
return a;
}
};
class d:public b
{
int c;
public:
void mul()
{
getab();
c=b*geta();
}
void display()
{
showa();
cout<<"b="<<b<<endl;
cout<<"c="<<c<<endl;
}
};
void main()
{
d t;
clrscr();
t.mul();
t.display();
t.mul();
t.display();
getch();
}
#include<iostream.h>
#include<conio.h>
class b
{
int a;
public:
int b;
void getab()
{
a=5;
b=10;
}
void showa()
{
cout<<"a="<<a<<endl;
}
int geta()
{
return a;
}
};
class d:public b
{
int c;
public:
void mul()
{
getab();
c=b*geta();
}
void display()
{
showa();
cout<<"b="<<b<<endl;
cout<<"c="<<c<<endl;
}
};
void main()
{
d t;
clrscr();
t.mul();
t.display();
t.mul();
t.display();
getch();
}

Comments
Post a Comment