Program related to Object Slicing : Why the output is not coming In Base a=2 ?

View previous topic View next topic Go down

Program related to Object Slicing : Why the output is not coming In Base a=2 ?

Post by iamdsc_0410 on Thu May 04, 2017 11:04 pm

Code:
//Object Slicing
#include<iostream>
using namespace std;
class Base
{
protected:
int a;
public:
Base(int x)
{
a=x;
}
void show()
{
cout<<"\nIn Base :a="<<a;
}
};
class Derived : public Base
{
private:
int b;
public:
Derived(int x,int y):Base(x)
{
b=y;
}
void show()
{
cout<<"\nIn Derived :a="<<a<<" and b="<<b;
}
};
int main()
{
Base B(5);
Derived D(2,3);
B.show();
return 0;
}
avatar
iamdsc_0410

Posts : 14
Join date : 2017-04-11
Age : 19
Location : IIIT Kalyani

View user profile

Back to top Go down

Re: Program related to Object Slicing : Why the output is not coming In Base a=2 ?

Post by akarshsomani on Fri May 05, 2017 7:36 am

Code:
//Object Slicing
#include<iostream>
using namespace std;
class Base
{
protected:
int a;
public:
Base(int x)
{
a=x;
}
void show()
{
cout<<"\nIn Base :a="<<a;
}
};
class Derived : public Base
{
private:
int b;
public:
Derived(int x,int y):Base(x)
{
b=y;
}
void show()
{
cout<<"\nIn Derived :a="<<a<<" and b="<<b;
}
};
int main()
{
Base B(5);
B.show();
Derived D(2,3);
D.show();
B=D;
B.show();
return 0;
}

akarshsomani

Posts : 21
Join date : 2017-04-04

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum