Pass-by-value does not change local variable of calling functions - Java Object Oriented Design

Java examples for Object Oriented Design:Method

Description

Pass-by-value does not change local variable of calling functions

Demo Code

public class Main{
  static void F(double x) {
    x = 3; // Here is the catch. Take care of pass-by-value.
    System.out.println("Before exiting F, value of x:" + x);
  }/*from   w  ww.  j  a v a2s .  c om*/

  public static void main(String[] args) {
    double x = 5;
    F(x);
    System.out.println("value of x:" + x);
  }
}

Result


Related Tutorials