Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.48 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class PassPrimitiveByValue
  2. {
  3.  static int x = 3;
  4.  
  5.  // change parameter in passMethod()
  6.  public static void passMethod(int p)
  7.  {
  8.   p = 10;
  9.   System.out.println("Right now pass method is invoked and its parameter's value is: " + p);
  10.  }
  11.  
  12.  public static void main(String[] args)
  13.  {
  14.   //invoke passMethod() with x as argument
  15.   passMethod(x);
  16.            
  17.   // print x to see if its value has changed
  18.   System.out.println("After invoking passMethod, x = " + x);       
  19.  }
  20. }