Deep Copying Error

paisley

New Member
Dea All,I have the following:\[code\]class test { int x = 6; int y = 7; private int getX() { return x; } private int getY() { return y; } public test copy() { test myTest = new test(); myTest.x = getX(); myTest.y = getY(); return myTest; }}\[/code\]However, when I then execute:\[code\]test a = new test();test b = a.copy();b.x = 17;System.out.println(a.x);\[/code\]The result is still 17. However, shouldn't deep copying prevent this?Anybody who can help me?
 
Back
Top