See the test code:
class Node
{
int num = 0;
}
class TestPassByReference
{
void increaseByOne(Node N)
{
N.num++ ;
}
public static void main(String args[])
{
Node N = new Node() ;
TestPassByReference T = new TestPassByReference() ;
T.increaseByOne(N) ;
System.out.println("num = "+N.num) ;
T.increaseByOne(N) ;
System.out.println("num = "+N.num) ;
T.increaseByOne(N) ;
System.out.println("num = "+N.num) ;
}
}
Which gives the result:
num = 1
num = 2
num = 3
The problem here, is that since Java is call by value then the num attribute of Node should have remained 0.
I think that this is due to creation of an object T, which would have contained an object N. But there is no attribute in T to save a Node like object. So how is this happening?
Any help is nefariously appreciated.
Moon.