Pass by Reference in java
-Passing the address or sending the copy of reference.
-If any changes in copied method ,it affect the original method.
-Pass By Reference is based on the object of a class or a object like
int[] a=new int[10];
program:
public class passarray {public static void main(String[] a)
{
int[] array={1,2,3,4,5};
System.out.println("effect of passing reference to entire array:\n"+"the value of the original array are:");
for(int b:array)
{
System.out.printf("%5d",b);
}
modifyarray(array);
System.out.println("\nthe value of the modified array are:");
for(int b:array)
{
System.out.printf("%5d",b);
}
}
public static void modifyarray(int[] array2)
{
for(int count=0;count<array2.length;count++)
{
array2[count]*=2;
}
}
}
output:
effect of passing reference to entire array:the value of the original array are:
1 2 3 4 5
the value of the modified array are:
2 4 6 8 10
Ask your Forums and Questions in the Comment box (mention your main Id).
0 comments:
Post a Comment