Sunday 17 February 2019

Write a Program to perform Single Inheritance in C++

  Program to Perform Single Inheritance in C++


1. Open a c++ software and write the code given below to perform single inheritance.


#include<iostream.h>                        

#include<conio.h>



class A   //Base class

{

public: void showA()
{
 cout<<"\nhello this is Base class A";
}
};
class B: public A     //Derive class   inheriting Base class
{
  public: void showB()
  {
   cout<<"\n hello thios is Derive class B";
  }
};
void main()
{ clrscr();
 B obj;
 obj.showB();
 obj.showA();   //calling function of base class
 getch();
}

2. Now save the file with .cpp extension.

3. Now compile and run the code and output screen will be like this:-

No comments:

Post a Comment

DBMS NOTES UNIT 3

                                                              UNIT 3  ER (Entity Relationship) An entity-relationship model is known as an E...