Java methods pass by value and pass the site

With regard to the method JAVA-value and pass the site.

class Emp{
 static void change01(int a) {
  a = 8;
 }
 static void change02(int[] a) {
  a[0] = 8;
 }
 public static void main(String[] args) {
  /*int x = 5;
  System.out.println("Before changes:x="+x);
  change01(x);
  System.out.println("After the change:x="+x);*/

  int[] y = {5};  
  System.out.println("Before changes:y[0]="+y[0]);
  change02(y);
  System.out.println("After the change:y[0]="+y[0]);
 }
}

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(java)