PROGRAM TO SHOW SINGLE INHERITANCE

by - December 20, 2018

/*WRITE A PROGRAM TO SHOW SINGLE INHERITANCE*/


#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class B
{
int a;
public:
int b;
void get_ab();
int get_a();
void show_a();
};
class D:public B
{
int c;
public:
void mul();
void display();
};
void B::get_ab()
{
a=5;
b=10;
}
int B::get_a()
{
return a;
}
void B::show_a()

{}
void D::mul()
{
c=b*get_a();
}
void D::display()
{
cout<<"\na="<<get_a();
cout<<"\nb="<<b;
cout<<"\nc="<<c;
}
int main()
{
clrscr();
D d;
d.get_ab();
d.mul();
d.show_a();
d.display();
cout<<"\nafter b=20";
d.b=20;
d.mul();
d.display();
getch();
}

----------------------------------------------------------
OUTPUT:-

You May Also Like

0 comments