Sunday 14 April 2013

CONSTRUCTOR IN INHERITANCE

#include<iostream.h>
#include<conio.h>
#include<dos.h>
class tmp
{

  public:
     int d,c;
     tmp::tmp(int i,int q)
     {
      d=i;
      c=q;
     };

     int sum2()
     {
       return(d+c);

     };

};

class temp:public tmp
{
  public:
      int a,b,sum;
      temp(int m,int n,int x,int y):tmp(m,n)
      {
    a=x;
    b=y;

      };
      int sum1()
      {
       sum=a+b;
       return(sum);
      };

};

void main()
{
 int ans;
 clrscr();
 temp t1(10,20,30,40);

 ans=t1.sum1();
 cout<<"\n\t\tYOUR ANSWER FROM TEMP CLASS::>"<<ans;
 ans=t1.sum2();
 cout<<"\n\t\tYOUR ANSWER FROM TMP CLASS::>"<<ans;

 getch();
}

No comments:

Post a Comment

How to change Background color by selecting color from Listview

activitymain.xml file::> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xm...