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