overloading and overriding in Java

Source: Internet
Author: User

Overloading (overloading)
    1. Method overloading is a means for a class to handle different types of data in a uniform manner. Multiple functions with the same name exist at the same time, with different number/types of parameters. Overloaded overloading is a representation of polymorphism in a class.
    2. Java's method overloading is that you can create multiple methods in a class that have the same name but have different parameters and different definitions. The method of invocation is to determine which method to use by passing the different number of arguments and parameter types to them, which is polymorphism.
    3. When overloaded, the method name is the same, but the parameter type and number are different, and the return value type can be the same or different. The return value type cannot be used as a distinguishing criterion for distinguishing overloaded functions.
Rewrite (overriding)
    1. The polymorphism between the parent class and the subclass, redefining the function of Frey. If you define a method in a subclass that has the same name and parameters as its parent, we say that the method is overridden (overriding). In Java, subclasses can inherit methods from the parent class without having to rewrite the same method. But sometimes, subclasses do not want to inherit the parent class's method, but want to make some changes, this need to adopt the method of rewriting. Method overrides are called method overrides.
    2. If a method in a subclass has the same method name, return type, and parameter table as a method in the parent class, the new method overwrites the original method. If you need a method from the parent class, you can use the Super keyword, which references the parent class of the current class.
    3. A subclass function must not have less than Fred's orientation modifier; an overriding method can only exist in an inheritance relationship, overriding a non-private method that overrides a parent class. Polymorphism is a feature of object-oriented programming and is independent of method.
Summarize

Overloading-There are different parameter lists (static polymorphism) and when subclasses inherit the same method as the parent class, enter the data, but to make a response different from the parent class, you overwrite the parent class's method-that is, override the method in the subclass-same parameter, different implementation (dynamic polymorphism)

overloading and overriding 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.