Since a is a Client object, this will work just fine. Let me clarify:
a is a "variable" of type Person, it can hold an "object" of any type from Person to any of its child classes.
c is a "variable" of type Client and may contain an "object" of any type from the Client to any of its child classes.
What you did puts the "object" of the Client in the "variable" Person. Wherever you move this object, it will always be a Client object. So, we need to keep in mind that even if you put the โobjectโ of the Client in a โvariableโ of type Person, the type of the object is still the client. In the following statement, you simply transferred the object to the correct type.
The variable is the same as the basket. It may contain anything less than it. If you pull an object out of the basket and put it in another basket, the object will still remain the same.
source share