Java Learning (ix) overloading and rewriting

Source: Internet
Author: User
overloading: one difference. Method names are the same, parameter lists are different. Other parts of the method, such as the method return value type, modifier, and so on, have no relation to the method overload. The reason why the overloads cannot be distinguished by the return value is that there are now two methods int f (), String f (), when we call the F () method, if we specify its return type, int a = f (), then the int f () method is called, but when we direct F () , it cannot be distinguished, so the overload cannot be determined by the difference in the return value.
Rewrite: Two with two small one big.         Both: The method name is the same and the formal parameter list is the same.         Two small: The subclass method return value type should be smaller or equal than the parent class method return value type, the subclass method declaration excludes exceptions that are less or equal than the exceptions thrown by the parent class method. A large: The subclass method should have greater or equal access to the parent class method, especially to point out that both the overriding method and the overridden method are either class methods or instance methods, not one class method and one instance method.

Java Learning (ix) overloading and rewriting

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.