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
What is inheritance and how many types of inheritance?
What is abstraction in oop with example?
Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?
Why is polymorphism needed?
What is abstraction encapsulation?
What is difference between inheritance and polymorphism?
Write a java applet that computes and displays the squares of values between 25 and 1 inclusive and displays them in a TextArea box
Why do we use oops?
What is multilevel inheritance explain with example?
What is polymorphism in oop example?
What is encapsulation process?
If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?
What is difference between multiple inheritance and multilevel inheritance?
What is destructor in oop?
What is abstraction oop?