Object Slicing, Is it advantage ?

Posted by harigm on Stack Overflow See other posts from Stack Overflow or by harigm
Published on 2010-03-05T18:47:41Z Indexed on 2010/03/11 5:53 UTC
Read the original article Hit count: 351

Filed under:
|
|
|
|

Object slicing is some thing that object looses some of its attributes or functions when a child class is assigned to base class. Some thing like

Class A{

}
Class B extends A{

}

Class SomeClass{
A a = new A();
B b = new B();

// Some where if might happen like this */
a = b; (Object slicing happens)

}

Do we say Object slicing is any beneficial in any ways? If yes, can any one please tell me how object slicing be a helpful in development and where it might be helpful?

© Stack Overflow or respective owner

Related posts about java

Related posts about slicing