Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Object data overlapping. (http://www.go4expert.com/forums/object-data-overlapping-t25918/)

Anerxomounos 27May2011 15:53

Object data overlapping.
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 18Jun2011 00:22

Re: Object data overlapping.
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 18Jun2011 20:08

Re: Object data overlapping.

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.

All times are GMT +5.5. The time now is 02:13.