问题
Can C++ slicing apply to other languages too, like Java/C#?
回答1:
Slicing means that if you assign a subclass instance to a superclass variable, the extra information contained by subclass is "sliced" off, because the superclass variable doesn't have the extra space to store this extra information of the subclass.
This doesn't happen in Java nor with C#, because all object variables are references; when you assign a subclass instance to a superclass variable, you actually just copy the reference; the subclass object itself remains intact.
来源:https://stackoverflow.com/questions/536267/c-slicing-in-java-c-sharp