Common ways to learn Java tutorials overload

Source: Internet
Author: User

Learn to program the Java Tutorial common method overload published, Welcome to visit through the xuebiancheng8.com

First look at what is a common method overload, first look at an example

public class person{

String username;

int age;

public void Hello () {

System.out.println ("Hello");

}

public void Hello (String username) {

System.out.println ("Hello" +username);

}

public void Hello (int.) {

System.out.println ("Hello" +age);

}

}

Then there is the following code:

Person P =new person ();

P.hello ();

P.hello ("Zhang San");

P.hello (20);

Output Result: Hello

Hello, Zhang San.

Hello, 20

The above example is the common method overload, their common feature is the same method name, the parameter list is different. The method that is called is determined by the parameters of the call.

Common method overloads require the following characteristics:

The method name is the same, the argument list must be different, and the access control and return values are not related.

There are a few things that are different in the parameter list

1. Different number of parameters

2. Parameter list order is different

3. Different types of parameters

Any of these features can be overloaded.

For more Java method overloaded content, please visit xuebiancheng8.com

The specific URL is

Http://xuebiancheng8.com/play/goodgoodstudy_96_daydayup.html


Common ways to learn Java tutorials overload

Related Article

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.