the code simply stores dataInterest type objects into the dlist[] of nodeobj[1] and nodeobj[2]
I want to create gptr for each nodeobj[]'s dlist[] .so that i can refer to it as nodeobj[1].dlist[0].gptr.value and nodeobj[2].dlist[0].gptr.value........but the value for both these pointers comes out to be the same,although i tried checking for nodeobj[1].dlist[0] and nodeobj[2].dlist[0] ,both of them are different .
public class mhand { public static node[] nodeobj; public static void main(String[] args) { boolean onetime=true; nodeobj=new node[5]; nodeobj[0]=new node(1,2); nodeobj[1]=new node(6,6); nodeobj[2]=new node(2,9); nodeobj[0].nlist[0]=nodeobj[1]; //putting into node 0's neigbor list node 1 and 2 nodeobj[0].nlist[1]=nodeobj[2]; mhand m=new mhand(); while(true) { if(onetime) //for storing dobj into dlist { packet pobj=new packet(3,0); m.n2pkt(pobj); onetime=false; nodeobj[2].dlist[0].gptr.value=8; //fixed value } nodeobj[1].dlist[0].gptr.value++; //incrementing value fo one pointer m.call(); }} public void n2pkt(packet pobj) // for making dobject and puting into dlist { dataInterest dobj=new dataInterest(pobj.type,pobj.senderid) ; for(int i=0;i<5;i++) { if((nodeobj[0].nlist[i]!=null)){ nodeobj[0].nlist[i].pkt[0]=pobj; nodeobj[0].nlist[i].dlist[0]=dobj; nodeobj[0].nlist[i].iFlag=true; System.out.println("printing for index "+i); } } } public void call() //prints pointer values { System.out.println("print for node 1 "+nodeobj[1].dlist[0].gptr.value); System.out.println("printing for node 2 "+nodeobj[2].dlist[0].gptr.value); } } public class node { boolean iFlag=false; int x; int y; node nlist[]=new node[5]; public dataInterest[] dlist=new dataInterest[5]; dataInterest ptr=new dataInterest(); packet[] pkt=new packet[1]; public node(){} public node(int a,int b) { x=a; y=b; } } public class dataInterest { public Gradient[] myglist=new Gradient[5]; int value=0; int type; int id; public Gradient gptr=new Gradient(); public dataInterest(int v,int c) { type=v; id=c; } public dataInterest(){} } public class Gradient { int id; int value=0; public Gradient(int a) { id=a; } public Gradient() { } } public class packet { int senderid; int type; public packet(int a,int b) { type=a; senderid=b; } }