Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is object slicing?

Answer Posted / rahul

execute this program and you will get your answer

class base
{
public int i,j;
}
class drived extends base
{
public int k;
}
class main
{
public static void main(String[] s)
{
base b = new base();
drived d = new drived();
b.i=10;
b.j=20;
System.out.println("this is class base i=10,j=20");
System.out.println("i =" +b.i);
System.out.println("j =" +b.j);
System.out.println("this is class drived i=100,j=200,k=300");
d.i=100;
d.j=200;
d.k=300;
System.out.println("i =" +d.i);
System.out.println("j =" +d.j);
System.out.println("k =" +d.k);
b=d;

System.out.println("after the assignment");
System.out.println("i =" +b.i);
System.out.println("j =" +b.j);
//System.out.println("k =" +b.k);
System.out.println("even though i am calling i and j using b object it is showing d values and you cannot call k this is called object sclicing object d got scliced now you cannot access k after the assignment of d into b");
}
}

Is This Answer Correct ?    7 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we create object of interface?

1133


Why is static class not inherited?

1108


Why do we use class?

1085


What are properties in oop?

1080


What is the difference between abstraction and polymorphism?

1091


INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?

2204


What is the oops and benefits of oops programming?

974


write a program to find 2 power of a 5digit number with out using big int and exponent ?

2379


c++ program to swap the objects of two different classes

2415


Can destructor be overloaded?

1031


What is interface in oop?

1126


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

3223


How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction

2138


What is overloading and its types?

1168


write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).

2154