Overloading and overwriting methods in Java (essay 01)

Source: Internet
Author: User

method Overloading (Overlord). Method overloading: means that in the same class, it is allowed to have more than one method of the same name, as long as their argument list is different, regardless of the modifier and return value type (for example, constructing method overloads). 。parameter list: The number is different, the data type is different, the order is different;。Overloaded method Invocation: The JVM invokes different methods through the parameter list of the method. The above three methods are in the same class as the premise, overloadmethod Overrides (also called method overrides). Method overrides: When a method that is identical to the parent class appears in a subclass (the return value type, the method name and the parameter list are the same), overrides appear, overriding the effect. The declaration is unchanged and is re-implemented. 。 Precautions1. The subclass method overrides the parent class method and must be guaranteed to be greater than or equal to the parent class permission ( interview selection question ) 2. The subclass method overrides the parent class method, returns a value type , and the function name and argument list are identical. 3. Return value type when learning polymorphism, the subclass method overrides the parent class method, and the return value type is less than or equal to the parent class method (This is a pit note) For example, the following codePublic class Fu { Public Fu Show () { System. out. println ("Fu Show"); return new Fu ();     }}Public class Zi extends fu{ @Override Public Zi Show () { System. out. println ("zi Show"); return new Zi ();     }

Overloading and overwriting methods in Java (essay 01)

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.