For the program given below, write statements to call display function from base and
derived class in main.
class base
{
int x;
public:
base (int a){x=a;}
void display ( )
{ cout <<x<<"\n";}
};
class derived :public base
{ int d;
public:
derived (int a, int b): base (a)
{ d=b; }
void display ( )
{cout <<d;}
};
int main ( )
{ derived D(10,20);
return 0;
}
#include<iostream>
using namespace std;
class base
{
int x;
public:
base(){
}
base (int a){
x=a;
}
void display ( )
{
cout <<x<<"\n";
}
};
class derived :public base
{ int d;
public:
derived (int a, int b): base (a)
{
d=b;
}
void display ( )
{
cout <<d;
}
};
int main ( )
{
base b(5);
b.display();
derived D(10,20);
D.display();
return 0;
}
Comments
Leave a comment