what is object slicing?

Answer Posted / debashis mishra,india,orissa

if an object of a derived class is assigned to a base class
object,the compiler accepts it.but it copies only the base
portion of the object
class base
{
public:
int i,j;
};
class derived : public base
{
private:
int k;
};
int main()
{
base b;
derived d;
b=d;
return o;
}
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 doesnot be copied. on the effect object d got sliced.

Is This Answer Correct ?    46 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Templates mean

1822


What is polymorphism used for?

770


What is encapsulation c#?

804


What is object and class in oops?

777


What is overriding in oops?

819


What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?

1887


What is static in oop?

820


What is the real time example of encapsulation?

789


Why do we need oop?

871


What does enum stand for?

858


What is data binding in oops?

822


What is a null tree?

856


What is polymorphism in oop example?

723


Can we override main method?

833


How do you achieve polymorphism?

818