confuse PassByReference and PassByValue in java method -


this question has answer here:

i have 2 classes. first class call call method(with parameter) inside in second class. want know when parameter pass , copy myclass ref or it pass reference.

public class newclass  {     public static void main(string[] args)     {         myclass obj = new myclass();         obj.val = 1;         obj.call(obj);         system.out.println(obj.val);     } }   public class myclass  {     public int val;     public void call(myclass ref)     {         ref.val++;     } } 

the output 2. understanding is pass refernece. please confirm answer. thank much.

java passes values. example misleading.

if passed references, if did:

public void call(myclass ref) { ref = new myclass(); } 

then ref change; , doesn't.

what pass value object reference.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -