what is object slicing
Answers were Sorted based on User's Feedback
Answer / subhashish saha
When you try to assign derived class object to an object of
base class, it takes the elements that has relivance with
respect to the base class and slices off the remaining
thing. this is object slicing...
Is This Answer Correct ? | 27 Yes | 1 No |
Answer / 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 |
Answer / ravi
OBJECT SLICING IS ALSO USED IN THE VIRTUAL FUNCTION
TO USE TO ACCESS THE DATA MEMBER OF DRIVED CLASS
Is This Answer Correct ? | 0 Yes | 9 No |
What is multiple inheritance ?
17 Answers Blue Star, C DAC, CDAC, Impetus, Ness Technologies, Softvision Solution,
Whats is abstraction in oops?
What is overloading in oop?
What does and I oop mean?
Write A Program using Single and Multiple Inheritance.
what is the use of classes in c++;
What are the 5 oop principles?
i have to create a view in SQL as like in ORACLE DATA EXPRESS EDITION
Which keyword is written to use a variable declared in one class in the other class?
What is a class?
32 Answers Infosys, TCS, Thylak,
to find out the minimum of two integer number of two different classes using friend function
why we are declare the function in the abstract class even though we are declaring it in Derived class?