Rewriting of the basic Java knowledge

Source: Internet
Author: User

1. Overriding the method: rewrite overwrite

1. Occurs in a parent-child class, the method name is the same, the parameter list is the same, the method body is different.

2. When the override method is invoked, look at the object type

3. Follow the "two same two small, one big principle

3.1 Two identical: Method name is same, parameter list is same

3.2 Two Small

3.2.1 Derived class returns a value type less than or equal to a superclass method: void and base type must be equal, reference type is less than or equal to

The 3.2.2 derived class throws an exception that is less than or equal to the superclass method.


2. Overrides are different from overloading:

2.1 Override: Occurs in a parent-child class, with the same method name, the same argument list, and a different method body.

Follow run-time bindings to see object type invocation methods

2.2 Overloads (Overload): occurs in a class with the same method name, different parameter lists, and different method bodies.

Follow the compile-time bindings to see the parameter/reference binding method.

Rewriting of the basic Java knowledge

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.