Results 1 to 4 of 4
  1. #1
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default Question about Array in class

    Can you set the size of the array in the modifier method? I have it like this and I get an error.

    Java Code:
    //Data Field
    private double[] scoresArray;
    
    // Modifier Methods
       	public void setScoresArray(int j) {
       	    this.scoresArray[j];
       	}

  2. #2
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Question about Array in class

    If You want to create instance of Array object, You should say:
    Java Code:
    this.scoresArray = new double[j];

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

    Default Re: Question about Array in class

    Quote Originally Posted by kraigballa View Post
    Can you set the size of the array in the modifier method?
    Yes you can.


    I have it like this and I get an error.

    Java Code:
    //Data Field
    private double[] scoresArray;
    
    // Modifier Methods
       	public void setScoresArray(int j) {
       	    this.scoresArray[j];
       	}
    But not like that. That's not how you initialize an array, but rather you'd do something like so to initialize one, right?:

    Java Code:
    int[] myArray = new int[10];
    Or if myArray is declared elsewhere as happens in your example:

    Java Code:
    myArray = new int[10];

    You're missing all of this.

  4. #4
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default Re: Question about Array in class

    I got ya. Thanks both of you!!

Similar Threads

  1. Replies: 0
    Last Post: 05-12-2011, 08:04 PM
  2. Array question..
    By gerarda in forum New To Java
    Replies: 14
    Last Post: 03-02-2011, 02:42 AM
  3. Question about array
    By hei1233212000 in forum New To Java
    Replies: 2
    Last Post: 09-18-2010, 04:55 PM
  4. Replies: 8
    Last Post: 03-21-2009, 10:34 AM
  5. Array question
    By McChill in forum New To Java
    Replies: 5
    Last Post: 02-20-2009, 03:18 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
  •