Answer Posted / kar4you
When a Derived Class object is assigned to Base class, the
base class' contents in the derived object are copied to
the base class leaving behind the derived class specific
contents. This is referred as Object Slicing. That is, the
base class object can access only the base class members.
This also implies the separation of base class members from
derived class members has happened.
class base
{
public:
int i, j;
};
class derived : public base
{
public:
int k;
};
int main()
{
base b;
derived d;
b=d;
return 0;
}
here b contains i and j where as d contains i, j& k. On
assignment only i and j of the d get copied into i and j of
b. k does not get copied. On the effect object d got sliced.
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
What are the components of marker interface?
what's the basic's in dot net
Why do we need polymorphism in c#?
Write a c++ program to display pass and fail for three student using static member function
What is oops and its features?
Can destructor be overloaded?
Why is destructor used?
What is encapsulation in oop?
write a program to find 2^n+1 ?
What are the two different types of polymorphism?
Prepare me a program for the animation of train
How to call a non virtual function in the derived class by using base class pointer
Why is there no multiple inheritance?
What are the 3 pillars of oop?