manish ghildiyal wrote:Indded defualt value of int array is 0 but in your modfiy method aren't you incrementing the first member of array?
manish ghildiyal wrote:..additionally
in your first case you are passing a primitive and not a reference...so when copying of
argument happens then you get two different entities which are in no way connected.So
modifying one doesn't impact other in any way.
manish ghildiyal wrote:Hi Arjun,
What I mean to say is that variable a which you pass as argument (to modify method)
in main method is copied when modfiy method is invoked...so variable which is actually modified inside modify method is not the variable a of main method, its just
a copy of it...so inside modify method you are not incrementing variable a of main method but rather a copy of it which is local to modiy method.
So variable a of main method reamains unincremented.
I think I got it. Is it now correct to generalise this and say that if i pass a primitive (and not a reference) to any method, the method actually works on a copy (BY VALUE!) of that variable and not on the original?
We now have two variables (the original one and one with the method) both named s but one with value 5 and the other with value 6. is this allowed?