Wednesday, 1 April 2015

U5P1

Program to implement Single Inheritance.

 #include<iostream.h>  
 #include<conio.h>  
 class one  
 {  
      public:  
      int a,b;  
      void fun_one()  
      {  
           a=15; b=20;  
           cout<<"\nFunction of class ONE called....";  
           cout<<"\nA = "<<a<<"\nB = "<<b;  
      }  
 };  
   
 class two : public one  
 {  
      public:  
      void fun_two()  
      {  
           cout<<"\nFunction of class TWO called....\nTotal = "<<a+b;  
      }  
 };  
   
 void main()  
 {  
      clrscr();  
      two obj;  
      cout<<"\nObject of class TWO created....";  
      cout<<"\n\nAccessing Base Class function....";  
      obj.fun_one();  
      cout<<"\n\nAccessing Derived Class function....";  
      obj.fun_two();  
      getch();  
 }  

Output :

No comments:

Post a Comment