Results 1 to 4 of 4
  1. #1
    Jarzka is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Question Swapping object pointers?

    Hi

    I would like to know why my code doesn't work

    Human human1 = new Human("Matti");
    Human human2 = new Human("Teppo");
    human1 = human2;
    System.out.println(human1.getName()); // Prints Matti instead of Teppo O_o
    Last edited by Jarzka; 05-28-2012 at 10:15 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Swapping object pointers?

    I don't see the source of your problem in the code posted above. Are you sure that this is the code that is executed?
    What does your Human class look like?

  3. #3
    Jarzka is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Swapping object pointers?

    Damn, now it works. Maybe I just forgot to compile the program again. Please delete this post :P

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. needs a few pointers...
    By PostConsumerWat in forum New To Java
    Replies: 4
    Last Post: 04-21-2012, 12:27 AM
  2. Can pointers as to what's wrong?
    By BrianS in forum Java Applets
    Replies: 0
    Last Post: 03-14-2012, 06:33 AM
  3. Replies: 1
    Last Post: 10-15-2010, 01:22 AM
  4. object new and pointers error
    By hydride in forum New To Java
    Replies: 2
    Last Post: 04-06-2010, 06:15 PM
  5. Pointers
    By ravian in forum New To Java
    Replies: 5
    Last Post: 11-28-2007, 01:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •