Single Level Inheritance With Example Programming

Explain Single Level Inheritance With Example Programming






Single Level Inheritance :-
1)    Here there is one Base Class and one Derived Class.
2)    Syntax :-     class  child-class-name  :  <access-mode> parent-class-name { definition code for the child class } ;
Example :
#include<iostream.h>
#include<conio.h>
class A
{
 char name[20];
 int roll;
 public:
 void getbase()
 { cout<<"enter roll and name:";
   cin>>roll>>name;
 }
 void showbase()
 { cout<<"\nname="<<name<<"\nroll="<<roll;
 }
};
class B:public A
{float h,w;
 public:
 void getd()
 { getbase();
   cout<<"enter height and weight:";
   cin>>h>>w;
 }
 void showd()
 { showbase();
   cout<<"\nheight="<<h<<"\nweight="<<w;
}
};
void main()
{
 clrscr();
 B b;A a ;
 //a.getbase();
 b.getbase();
 b.getd();
 b.showd();
 //a.showbase();
 getch();
}


Labels: