Java Exercises 2

Source: Internet
Author: User

What is the difference between 1.Overload and override? Can overload change the return value type?

Override:

Refers to a method in which a subclass appears exactly the same as the parent class name, called Override.

However, the return value type cannot be changed.

Overload:

Refers to the same class where the name appears, but the formal parameters are not the same method, called Overload.

You can change the return value type.

Note:
Overload: Method Overloading
Override: Method Overrides

What do the 2.this keywords and super keywords stand for? And their respective usage scenarios and roles.

This

Refers to a member variable or a member method in the same class.

This.value;this.function ();

Super

Refers to a member variable or member method that references a parent class.

Super.value;super.function ();

But! 1. Parent class private variable cannot be inherited, so super! cannot be

2. The parent class private method cannot be called, so it cannot be super!

Java Exercises 2

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.