Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Problem with Test Program in Java Inheritance

Options
  • 01-03-2012 10:13pm
    #1
    Registered Users Posts: 377 ✭✭


    Just wondering if anyone could tell me the reason why I am having the following problem.

    I am after writing a Java inheritance program and a test system to ensure it works ok. Basically it is a Organisation which is has a Person class which is an ArrayList and from this we have 2 subclass Full time employee and Partime employee so I have the whole employee extends person etc.
    I also have to have a class for Name and Address.

    Anyway all these classes complie no errors but when I go to the Test system to display all of the people in the org or any specific employee some of their details won't display right. :mad: :confused:

    Age, gender etc all ok. It is the name and address fields which just show randon numbers and letters such as @2CF0a etc.

    Any idea where I might be going wrong would be appreciated.


Comments

  • Closed Accounts Posts: 2,300 ✭✭✭nice1franko


    You need to write a toString method for your objects


  • Registered Users Posts: 2,149 ✭✭✭dazberry


    libra02 wrote: »
    Age, gender etc all ok. It is the name and address fields which just show randon numbers and letters such as @2CF0a etc.

    Not a Java person, but that looks like a reference to a memory address, @HexNumber. After a quick google:
    If we look at the toString() implementation in the Object Class, it is simply:
       public String toString() {  
    return getClass().getName() + "@" + Integer.toHexString(hashCode());  
        }  
    

    D.


  • Registered Users Posts: 377 ✭✭libra02


    You need to write a toString method for your objects


    Thanks for the info but to tell you I never heard of the toString methods.

    So would I need to put it in the Organisation class which holds most of the methods for the test program or does it need to go into another class.

    Apologies if that sounds like a very stupid question but considering Im only started Java 9 weeks ago it took me ages to work out the rest of the program and get it to mostly work I amazed I got this far.


  • Closed Accounts Posts: 2,300 ✭✭✭nice1franko


    see here for example: http://forums.techarena.in/software-development/1304002.htm

    post 3 there sums it up


Advertisement