Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the difference between overloading and rewriting in java

Shulou Source: shulou.com Published: 2022-06-02 08:31:36 11月20日 Update

This article will explain in detail what is the difference between reloading and rewriting in java. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

1. Define

Rewrite (override): the subclass rewrites the parent class method, (the return value type, method name and parameter list remain unchanged)

Overloading (overload): overloading is to create multiple methods in a class with the same method name but different parameters. The return type can be the same or different. (decide which method to use by passing different parameters when calling the method.)

two。 Difference

Method rewriting and overloading are different manifestations of java polymorphism. Rewriting is a manifestation of polymorphism between parent and child classes, and overloading can be understood as a specific form of polymorphism (class polymorphism).

What's the difference between overloading and rewriting in java is shared here. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Method different polymorphism parameter polymorphism same content subcategory article more knowledge article type yes between multiple forms is in quality reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia vpn Linux MariaDB