I have two classes. The first class call to call method(with parameter) that is inside in second class. I want to know when parameter pass , it copy to MyClass ref or it pass by 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 is 2. My understanding is it is pass by refernece. Please confirm my answer. Thank you very much.