The passing years, save the children: between objects under the assignment should be in the same type of why the first box assignment is not an error, the second frame will be an error, how do I change the second box?
CodePudding user response:
Can you understand so Subclass is on the basis of the parent class extension, in a sense a subclass of memory information is greater than (or at least not less than) the parent class of memory information (more information on the memory of the parent information) So Parent class variables=subclass, less memory information, because the parent class variables after reduced the memory space of the subclass is assigned to the parent class variables, not cause memory cross-border (already belong to a subclass of memory space, how to narrow the memory still in legal space), so no problem Subclass=parent class variables, because the subclass of variable memory information, expand the memory space of the parent after assigned to subclass variables, can cause memory cross-border (extended to the originally do not belong to the memory of the parent), so there is a problem
CodePudding user response:
May be backwards compatible animal, that is, the upstairs said, parent and child classes, for an example of inappropriate, just like the relationship between the string and char, string=char and do not lose the details of the char, and char=the string is not possible