JAVA parameter and return type of the method
-
Into the reference method
-
Basic data types
-
Reference data types
Modifier return type method name (parameter type parameter name, parameter type parameter name ... ) {
// method body
return
} -
-
Method return types
-
the specific type of return xxx
-
If you do not return, the method returns the type to write void
Modifier void ⽅ method name ( parameter type parameter name, parameter type parameter name ...) {
// ⽅ method thereof
} -
example
1 package study2day;public class Student1 { 2 private int age; 3 public void setAge(int age){ 4 this.age =age; 5 } 6 public int getAge(){ 7 return age; 8 } 9 }
Note: The first one is the reference code
1 package study2day; 2 3 public class ParamTest { 4 public static void main(String [] args){ 5 ParamTest.calculate("5000",2000); 6 Student1 a = new Student1(); 7 a.setAge(10); 8 System.out.println("操作前="+a.getAge()); 9 changeAge(a); 10 System.out.println("操作后="+a.getAge()); 11 } 12 13 public static void calculate(String numbera,int numberb){ 14 System.out.println("numbera ="+numbera); 15 System.out.println("numberb ="+numberb); 16 } 17 public static void changeAge(Student1 hx){ 18 hx.setAge(27); 19 } 20 }