/*
State the output
*/
#include<iostream>
using namespace std;
class BaseClass
{
int x;
public:
void setx(int i)
{
x=i;
}
int getx()
{
return x;
}
};
class DerivedClass:public BaseClass
{
int y;
public:
void sety(int i)
{
y=i;
}
int gety()
{
return y;
}
};
int main()
{
BaseClass *p;
BaseClass baseObject;
DerivedClass derivedObject;
p=&baseObject;
p->setx(10);
cout<<"\n Base Object x: "<<p->getx();
p=&derivedObject;
p->setx(99);
derivedObject.sety(88);
cout<<"\n\n Derived object x: "<<p->getx();
cout<<"\n\n Derived Object y: "<<derivedObject.gety();
return 0;
}
State the output
*/
#include<iostream>
using namespace std;
class BaseClass
{
int x;
public:
void setx(int i)
{
x=i;
}
int getx()
{
return x;
}
};
class DerivedClass:public BaseClass
{
int y;
public:
void sety(int i)
{
y=i;
}
int gety()
{
return y;
}
};
int main()
{
BaseClass *p;
BaseClass baseObject;
DerivedClass derivedObject;
p=&baseObject;
p->setx(10);
cout<<"\n Base Object x: "<<p->getx();
p=&derivedObject;
p->setx(99);
derivedObject.sety(88);
cout<<"\n\n Derived object x: "<<p->getx();
cout<<"\n\n Derived Object y: "<<derivedObject.gety();
return 0;
}