Java Learning Note (18): polymorphic

Source: Internet
Author: User

What is polymorphic

The benefits of polymorphism

For example: Demand: A way for breeders to feed animals to feed animals

If there is no polymorphism, we will find that for different types of animals, we need to provide different feed methods to feed, when the demand changes, such as increasing the animals, it is necessary to increase the animal's feed, the code is not concise and elegant.

I just wanted to provide a feeding method to feed all types of animals, and to unify feeding behavior, it is time to introduce polymorphism, requiring only one feeding method to respond to changing needs.

Therefore, the role of polymorphism is to treat different sub-object as a parent, you can block different sub-class object implementation differences, the use of common code to adapt to the changing needs, to achieve universal programming.

Java Learning Note (18): polymorphic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.