Object data overlapping.

Anerxomounos's Avatar, Join Date: May 2011
Newbie Member
I have this code that i'm using to test if my program works, but all the Account type objects are somehow getting the same data inserted.
Account acc1 = new Account();
       Account acc2 = new Account();
       Account acc3 = new Account();
       acc1.insert("AAA", 1, 2, 3, 4, 5, 6);
It prints out : BBB 1 2 3 4 5.0 6.0
for all 3 of them, while it should print:
AAA 1 2 3 4 5.0 6.0
CCC 0 0 0 0 0.0 0.0
BBB 0 0 0 0 0.0 0.0

The Account class works perfectly, and I know this because it got 10/10 on my previous project.
Avenger625's Avatar, Join Date: Feb 2011
Go4Expert Member
Post the codes for insert() and setcode().
It is not possible to tell what was wrong from what u have posted.
Post some more parts of the code!!!
ewaldhorn's Avatar, Join Date: Feb 2010
Go4Expert Member

Since I haven't seen your source code, it's a bit difficult to figure out what's going on. You seem to be a new Java programmer, so perhaps your class is working, but it contains static variables?

See, static variables are shared by all instances of a class, which would explain why altering one class has an effect on the rest as well. Remove any static keywords you have in the declaration of your variables and see if that helps.