PROGRAM FOR SINGLE INHERITANCE USING PUBLIC

//program for single inheritance using public
#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()
{
 c=b*geta();
}
void display()
{
 cout<<"a="<<geta()<<endl;
 cout<<"b="<<b<<endl;
 cout<<"c="<<c<<endl;
}
    };
    void main()
    {
       d t;
       clrscr();
       t.getab();
       t.mul();1
       t.display();
       t.b=20;
       t.mul();
       t.display();
       getch();
     }

Comments

Popular Posts