They are both passed by *value*.  The *value* of an int is the int itself; 
this is true for all primitive types.  The *value* of a reference, however, 
is the pointer to the object.  The object itself is not copied, only the *
reference* to the object.  So, you had two pieces of code operating on the 
same object.

This also explains some of the odd behavior of the final keyword -- it 
works as you'd expect for primitives, since it is locking up the value 
itself.  But for references, it is only locking up that reference's *value*, 
not the object it points to.  For example, final arrays can have their 
elements modified, but the array reference itself can't change. 

Pat.

On Monday, June 24, 2013 12:15:21 PM UTC-5, Deepak Sharma wrote:
>
> Hello it seems so easy.. Isn't it??
>
> Lets start.. 
>
> we have in Java only pass by value not by reference.. 
>
> *public class Testing *
> *{*
> * public static void main(String[] args)*
> * {*
> * int a=5;*
> * System.out.println("values = " + a);*
> * value(a);*
> * System.out.println("values = " + a);*
> *
> *
> * }*
> *
> *
> * private static void value(int a)*
> * {*
> * a=10;*
> * System.out.println("values = " + a);*
> * *
> * }*
> *}*
> *
> *
> output : 
> values = 5
> values = 10
> values = 5
>
> Right?? 
>
> now come to the point 
>
>
> *public class Testing *
> *{*
> * public static void main(String[] args)*
> * {*
> * ResultSet rset= conn.createStatement().executeQuesry("....");*
> *
>
> *
> *
> value(rset);
> *
> *
>
> *
> *
> **
> // if here we try to access the rset, it says its close or something 
> else.. 
> *
> *               // Right?? if in Java there s o call by reference then 
> why local variable rset is not working here?? *
> * }*
> *
> *
> * private static void value(ResultSet a)*
> * {*
> * while(a.next())*
> * {*
> * ..*
> * ..*
> * ..*
> * }*
> * }*
> *}*
>

-- 
You received this message because you are subscribed to the Google Groups "Java 
Posse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/javaposse.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to