Java method coverage

Source: Internet
Author: User

The override method must meet multiple constraints:

1. the name, parameter signature, and return type of the subclass method must be the same as that of the parent method, parameter signature, and return type.

 

2. Subclass methods cannot reduce the access permissions of parent methods. However, the access permission can be expanded. For example, from default to public.

 

3. The subclass method cannot throw more exceptions than the parent method. However, you can throw fewer exceptions than the parent class, or do not throw an exception.

 

4. Method override only exists between the subclass and parent class. In the same class, it can only be overloaded and cannot be overwritten.

 

5. Static Methods of the parent class cannot overwrite non-static methods of the quilt class.

 

6. Static methods cannot be overwritten. However, subclasses can define static methods that are the same as parent classes, but they are only equivalent to a new method defined by subclasses.

 

7. The private method of the parent class cannot be overwritten by the quilt class.

 

8. The abstract method of the parent class can be overwritten by the quilt class in two ways: one is to implement the abstract method of the parent class by the subclass, and the other is to re-declare the abstract method of the parent class by the subclass.

 

9. Non-abstract methods of the parent class can be overwritten as abstract methods.

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.