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

What is the purpose of enum?

583


Which is better struts or spring?

624


How can you overcome the diamond problem in inheritance?

770


What is the point of polymorphism?

590


write a program that takes input in digits and display the result in words from 1 to 1000

1990






What is coupling in oops?

598


Can bst contain duplicates?

670


What does and I oop mean in text?

625


What is encapsulation example?

551


What is a function in oop?

633


write a program using c++ to implement single contiguous memory mangement techniques.display the content of the main memory after yhe allocation of jobs and percentage of the wastage of the main memory

2764


What is the importance of oop?

613


Why is there no multiple inheritance?

571


What is inheritance in simple words?

627


What is overriding in oops?

606