what is object slicing

Answers were Sorted based on User's Feedback



what is object slicing..

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

what is object slicing..

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

what is object slicing..

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

Post New Answer

More OOPS Interview Questions

What is super in oop?

0 Answers  


what is the use of template classes in c++

1 Answers  


which feature are not hold visual basic of oop?

0 Answers   Ignou,


String = "C++ is an object oriented programming language.An imp feature of oops is classes and objects".Write a pgm to count the repeated words from this scenario?

0 Answers   HCL,


Can we define a class within the interface?

0 Answers  






what is the definition of incapsulation

2 Answers  


what is an qt4 interface?

1 Answers   IBM,


What is encapsulation and abstraction? How are they implemented in C++?

0 Answers   Agilent, ZS Associates,


What is the real time example of inheritance?

0 Answers  


What are the 4 main oop principles?

0 Answers  


What does enum stand for?

0 Answers  


what is code for call by value and call by reference?

1 Answers  


Categories