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 |
DIFFRENCE BETWEEN STRUCTURED PROGRAMING AND OBJCET ORIENTED PROGRAMING.
what is the difference between class to class type conversion and copy constructor ?
#include <stdio.h> #include <alloc.h> #include <stdlib.h> #include <conio.h> void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.
What are the 4 pillars of oop?
OOP'S advantages of inheritance include:
Program to read a comment string
What is difference between oop and pop?
which is platform independent device used in computers
Can you inherit a private class?
What do we mean by a hidden argument in a function?
Petrol pump mgt. system: To design a program that display an interface for the sale of the Petrol and then make the entries at the backend in the database.
What is data binding?