如何在 Java 方法中按引用傳遞引數?


按引用傳遞引數是指使用一個帶引數的方法呼叫。透過此方法,引數值被傳遞給引數。

示例

public class SwappingExample {
   public static void swapFunction(int a, int b) {
      int c = a+b;
      System.out.println("Sum of the given numbers is ::"+c);
   }

   public static void main(String[] args) {
      int a = 30;
      int b = 45;
      swapFunction(a, b);
   }
}

輸出

Sum of the given numbers is ::75

更新於:2019-07-30

208 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.