This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Not quite right. It really depends on what you wanna do with the array. Do you wanna return an element value from the specific index? Or a fixed location everytime?
When you uses a setter method, where do you wanna set the new data into? A fixed position or an arbitrary position?
Usually, not always, setter methods have to take in a parameter, usually the data you wishes to assign to a variable. And a getter method has no arguments while returning the value that you're interested in obtaining.
Like Cheng stated, it depends on your application. Whether you are sorting or adding or indexing...etc the array then you would have different accessor and mutator methods. It looks like the methods that you have created are just putting numbers in the index and then you are trying to return the numbers. Remember that int is a primitive type and when you try to print out this list of numbers that you are adding in you will just get a memory location for the entire array. If you want to see the numbers then just change the get method to SOP the arr[i]. I would suggest something like this:
Gabe [ June 16, 2004: Message edited by: Gabriel White ]