6.java method

Source: Internet
Author: User

1. Use of methods
1> no parameter no return value







2> non-parametric return value

There can be only 1 return values

3> with parameter no return value

Parameters can be multiple, separated by commas. In addition to the basic data types, you can also have arrays, strings, etc.

4> with parameter return value


2 Method overloading

The basis for judging method overloading:

1, must be in the same Class 2, the same method name

3, the number of method arguments, the order or the type is different     4, and the modifier or return value of the method is not related

Public class helloworld {    public static void main (String[ ] args)  {        //  Create Objects          helloworld hello = new helloworld ();         //  Call the         hello.print method ();         //  call a method with a string parameter          Hello.print ("Ling");        //  call method with an integer parameter          hello.print (1);     }    public void  print ()  {        system.out.println ("Non-parametric Print method");     }    public void print (String name)  {        &nbSp System.out.println ("Print method with a string argument with the parameter value:"  + name);    }     public void print (int age)  {         System.out.println ("Print method with an integer parameter with the parameter value:"  + age);     }}


6.java method

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.