An instance of subclass will always have all the fields and methods of a superclass. Casting the subclass to superclass (i.e. (SuperClass) subclass
) will not remove the data, it will just tell the compiler to apply the rules for SuperClass, which means you will get a compile-time error if you try to access subclass' data. Nevertheless, you can still downcast it back to subclass or use reflection - the data is there. This is by design and you can't get away from it.
If you want to really "remove" the data of a subclass, you need to construct a new instance of a superclass, not subclass. The easiest way would be to add a constructor to superclass that takes a superclass as a parameter and copies all superclass-related data from it.