Java polymorphic instance code

Polymorphism is the ability of the same behavior to have multiple different forms or forms. Polymorphism is the same interface that uses different instances to perform different operations.

Polymorphism is the embodiment of multiple manifestations of objects, such as:

In reality, we press the F1 key:

If the help document of as 3 pops up in the flash interface, if word help pops up in the word interface, windows help and support pops up in the windows interface

Three necessary conditions for the existence of polymorphism

Inheritance overrides a parent class reference to a child class object

When calling a method in a polymorphic way, first check whether the method exists in the parent class. If not, the compilation error will occur; If so, call the method with the same name of the subclass.

Examples

Ask the output of this program. (D)

summary

The above is all about the Java polymorphic instance code in this paper. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site. If there are deficiencies, please leave a message to point out. Thank you for your support!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>