Consider the example(passing primitives)
int x = 0;
passingPrimitives(x);
System.out.println(x);
............
............
void passingPrimitives(int y)
{
y = 10;
}
After the method call the value of x is 0 and NOT 10. So primitives are passed by value
Another example (passing objects)
Object x=null;
passingObjects(x);
System.out.println(x);
............................
...........................
void passingObjects(Object y)
{
y = "Am i now Y?"
}
The value of x after the method call is null. A clear indication of objects are passed by value too in java.
No comments:
Post a Comment