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


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

Sai Subramanyam
Sai Subramanyam

Passionate, Curious and Enthusiastic.

Updated on: 30-Jul-2019

170 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements