Method overloads and overrides in Java and method modifiers

Source: Internet
Author: User
Tags modifiers throw exception

1. Method overload overloading, is in a class, there are multiple methods, the names of these methods are the same, but with a different parameter list, and the return value overloads, the method name is the same, but the parameter type and the number of arguments are different, the return value type can be the same, or can be a difference, You cannot determine whether a method is overloaded with a return value type. 2The . Method overrides the overriding, which is present between the parent class and the child class (1The method in the Kawai class has the same method name, return type, and parameter table as a method in the parent class, and the new method overrides the method in the parent class, such as to call the parent class method with the Super keyword (2The permission modifier for the overridden method of a subclass cannot be less than the parent class, or the rule that is greater than or equal to the parent class override method: (1), the argument list must be exactly the same as the overridden method, otherwise it cannot be called overridden but overloaded. (2), the returned type must always be the same as the return type of the overridden method, otherwise it cannot be called overriding but overloaded. (3), the restriction of the access modifier must be greater than or equal to the access modifier of the overridden method ( Public>protected>default>Private) (4), the overriding method must not throw a new check exception or a more generalized check exception than the overridden method declaration. For example: A method of the parent class declares a check exception ioexception, in overriding this method is not able to throw exception, can only throw IOException subclass exception, can throw non-check exception. Instead of overloading the rule: (1), must have a different list of parameters;2), can have a return type without scolding, as long as the parameter list is different;3), can have different access modifiers; (4), can throw different anomalies;

Permission modifiers

Method overloads and overrides in Java and method modifiers

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.