I understand the overloads and overrides in Java

Source: Internet
Author: User

In the program we use methods to implement the operation of the object, but the object may have different data types, at this time for different data types, the same operation, we can use the method of overloading, that is, the method name is the same, but with a different parameter list.

The overloads of a method can call methods depending on the data type of the passed parameter, or they can be designed according to the number of parameters.

Overloads must have different parameter lists, return types and access modifiers can be different, or you can throw different exceptions.

Overrides are used in the inheritance of subclasses to the parent class, and when we want to use the method in the parent class, but want to change the operation in the method body, we can use the rewrite.

The parameter list and return type of the overridden method must be the same as the overridden method, and the access modifier's limit cannot be less than the overridden method, and the overriding method cannot throw a new check exception or a more generalized check exception than the overridden method declaration.

I understand the overloads and overrides in Java

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.