Results 1 to 2 of 2
  1. #1
    shaztech is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Default How to create an array of objects which has integer field

    I am very new to JAVA and was trying to do the first exercise:

    Create an array A of GameEntry objects, which has an integer
    scores field, and we clone A and store the result in an array B. If we then immediately set A [4].score equal to 550, what is the score value of the GameEntry object referenced by B[4]?

    First I thought I will declare a variable of 'int scorse;'. Then create an array A of GameEntry like, GameEntry[] a = new GameEntry(); Cloning a into b would be like b = a.clone(); I can get the idea that both A[4] and B[4] will be pointing to same object if I do a=b; But I just can't understand how to implement(start and end) this problem. I don't seem to grasp the idea of putting things together.

    Any help would be really appreciated.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default Re: How to create an array of objects which has integer field

    Hi.
    This task shows that array is primitive type in Java. and when you make array clone you will do new array. about compare to objects you must override hashCode and equals methods in you object and then to use equals methods.
    Regard.
    Skype: petrarsentev
    http://TrackStudio.com

Similar Threads

  1. How to get Integer values from Text Field
    By aks_saxena in forum AWT / Swing
    Replies: 3
    Last Post: 04-09-2011, 01:00 PM
  2. How to create an array of objects
    By redmaverick in forum New To Java
    Replies: 7
    Last Post: 10-19-2009, 02:14 AM
  3. Replies: 1
    Last Post: 03-31-2009, 06:40 AM
  4. Replies: 1
    Last Post: 01-22-2009, 04:25 PM
  5. Help with define an integer field
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:32 AM

Posting Permissions

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