View RSS Feed

Java Array

arrays are passed by reference

Rate this Entry
by , 03-04-2012 at 10:20 AM (960 Views)
By reference, array is passed to functions. Or it is passed to original as a pointer. This shows that anything which happens to an array in a function would be affecting the original.

For understanding an array is passed by reference

Step 1) In editor, code shall be copied

Java Code:
class ArrayDemo {
  
   public static void passByReference(String a[]);
     a[1] = "Changed";
   }
  
   public static void main(String args[]){
      String []b={"Apple","Mango","Orange"};
      System.out.println("Before Function Call    "+b[0]);
      ArrayDemo.passByReference(b);
      System.out.println("After Function Call    "+b[0]);
   }
}
Step 2) Save, Compile & run the code. Observe output.

Submit "arrays are passed by reference" to Facebook Submit "arrays are passed by reference" to Digg Submit "arrays are passed by reference" to del.icio.us Submit "arrays are passed by reference" to StumbleUpon Submit "arrays are passed by reference" to Google

Categories
Arrays

Comments