what is object slicing?

Answer Posted / rsn

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.

Class Base
{
public:
int i;
};

class Derived : public Base
{
public:
int j;
};

int main()
{
Base Bobj;
Derived Dobj;
Bobj = Dobj; //Here Dobj contains both i and j.
//But only i is copied to Bobj.
}

Is This Answer Correct ?    126 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can private class be inherited?

623


Advantage and disadvantage of routing in telecom sector

790


why reinterpret cast is considered dangerous?

1907


What are properties in oop?

613


What are main features of oop?

639






What is for loop and its syntax?

599


Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.

704


Explain the advantages of inheritance.

677


What is overriding in oop?

553


What is oops and why we use oops?

573


How do you answer polymorphism?

580


What is encapsulation selenium?

556


Why do we use polymorphism in oops?

585


class type to basic type conversion

1843


What is a function in oop?

635