How do we pass parameters by value in a Java method?

Java 8Object Oriented ProgrammingProgramming

Passing Parameters by Value means calling a method with a parameter. Through this, the argument value is passed to the parameter.

Example

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);
   }
}

Output

Sum of the given numbers is ::75
raja
Published on 06-Feb-2018 00:57:20
Advertisements