• JAVA方法入参和返回类型


    • 方法入参

      • 基础数据类型

      • 引用数据类型

      修饰符 返回类型 方法名(参数类型 参数名,参数类型 参数名...){
      //方法体
      return
      }
    • 方法返回类型

      • return xxx 具体类型

      • 如果不用返回,则方法返回类型上写void

      修饰符 void ⽅方法名(参数类型 参数名,参数类型 参数名...){
      //⽅方法体
      }

    例子

    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 }

    注:第一块为引用代码

     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 }

     

  • 相关阅读:
    hdu4578线段树维护平方和,立方和(加,乘,赋值)或者珂朵莉树
    珂朵莉树(ODT老司机树)
    Codeforces Round #524 (Div. 2)D
    HDU1402 FFT高精度乘法模板题
    中国剩余定理poj1006
    POJ
    Install and Config MySQL 8 on Ubuntu
    Protobuf Examples
    Learning Thrift
    Flask Quickstart
  • 原文地址:https://www.cnblogs.com/jyuri/p/12078771.html
Copyright © 2020-2023  润新知