Coding Discussions
Would you like to react to this message? Create an account in a few clicks or log in to continue.

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

2 posters

Go down

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

Post by iamdsc_0410 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;
}
iamdsc_0410
iamdsc_0410

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

Back to top Go down

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

Post by akarshsomani 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

Back to top Go down

Back to top

- Similar topics

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