Java Override and Overload

Source: Internet
Author: User

Java Override and Overload

Rewrite:

Re-writing refers to the process in which the subclass re-writes the parent class method, as shown in

1: The parameter list cannot be changed.

2: The type of the return value cannot be changed.

3: if the parent class does not throw an exception, a forced exception cannot be thrown when the subclass overrides this method. If the parent class throws an exception, an advanced exception of the parent class exception cannot be thrown when the subclass overrides this method.

4: the access permission of the method after subclass rewriting cannot be lower than that of the method whose parent class is overwritten.

5: Methods declared as final cannot be overwritten.

6: Methods declared as static cannot be overwritten, but can be declared again.

7. The constructor cannot be rewritten.

8: when the child class and parent class are in the same package, the Child class can override all (excluding static and final modifier) Methods of the parent class. When the Child class and parent class are not in the same package, subclass can override the non-final method declared as public and protected for the parent class

Heavy Load

Overload means that in the same type, the method name is the same, the parameter list is different, and the return value type may be different.

1: The parameter list must be changed for the method after the overload.

2: The return type and access modifier can be changed.

3: You can declare or throw more advanced exceptions.

4: You can reload the parent class in the same class or subclass.

5: the return value cannot be used as the standard for definition of heavy loads.

Related Article

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.