Monday, 4 February 2013

inheritance in c++ part3


#include<iostream.h>
#include<conio.h>

class parent              //super class
{
protected:
int n;
public:
   parent()
{
   n=0;
   }

   parent(int p)       //-----------------1
   {
n=p;
   }

   void show()
   {
   cout<<"n= "<<n<<endl;
   }};

class child : public parent        //sub class
{
protected:
char ch;
public:
child()
   {
   ch='x';
   }

   child (char c,int m):parent(m)  //here v r recalling constuctor------1 and pasing m to p
   {
   ch=c;
   }

   void display()
   {
   cout<<"ch= "<<ch;
   }};

   void main()
   {
   child c1;
cout<<"c1 is: \n";
   c1.show();
   c1.display();
   child c2('w',100);
   cout<<"\n\nc2 is: \n";
   c2.show();
c2.display();

   getch();
   }

0 comments:

Post a Comment