aspose file tools
The moose likes Beginning Java and the fly likes array instantiation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "array instantiation" Watch "array instantiation" New topic
Author

array instantiation

Kat Cobb
Greenhorn

Joined: Oct 22, 2007
Posts: 2
I have to set up a constructor to go with my array program. One of my data members is "private int[] scores". My constructor is supposed to take an array of integers as a parameter. It then calls a setScore method passing it the parameter array. First, is it possible to instantiate an array without setting its bounds? I need to be able to enter a different amount of numbers each time I run the program, but I can't get it to compile without putting a bound in...ie: private int[]scores = new int[11]. Second, when I call the method, I know I put "setScores()" but how would I pass it the parameter array? Thanks.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

No, you cannot instantiate an array without setting its size. However, you can declare an instance variable without instantiating it, and then instantiate it in the constructor when you know the size...

[ December 01, 2007: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: array instantiation
 
Similar Threads
Array doubt
Cannot throw exception
ExamCram Qts
not sorting; getting null
Displaying Data