1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Object data overlapping.

Discussion in 'Java' started by Anerxomounos, May 27, 2011.

  1. Anerxomounos

    Anerxomounos New 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.
  2. Avenger625

    Avenger625 New 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!!!
  3. ewaldhorn

    ewaldhorn New 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.

Share This Page