java-interfaces and polymorphism-

enumerate

As long as the XX in switch(XX) is an enumeration type, then only the variables that have been predefined in the enumeration can be selected in the case.

Subclass to parent class (upcast)

Parent rotor class (downward transformation)
Parent rotor class, sometimes it works, sometimes it doesn't, so it must be forced.

own experiments

My doubt is:
the address value of this hero is exactly the same as the address value of my subclass adHero, so why can't this hero see the things of its subclass, they are all the same address! !

According to personal understanding: hero=adHero ; The reference type of hero on the left is different from the reference type of adHero on the right. So why can you assign adHero to a different type of hero?

Since it is an assignment, it is clear that the subclass is assigned to the parent class. Why can it be said that the subclass turns to the parent class. Is it possible to first convert the reference of the subclass to the reference of the parent class, and then copy it to hero? It seems to make
sense, but the strange thing is that, from the printing results, after copying, the address of the parent class reference and the subclass reference The address is exactly the same. So what is the difference between this conversion and the address referenced by the original subclass?



==================================================


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324970741&siteId=291194637
Recommended