Sorry, I know this answer is obvious but I suppose I'm just slow. Can anyone give me clear definitions of an instance variable and a constructor?
Instance variables:
Your class will need an instance variable named numbers that is a one-dimensional array. The size of the array will be determined by the constructor. You may, or may not, find it useful to have other instance variables.
Constructors:
You will write two constructors.
One constructor will be a default constructor that has no arguments. It will create an array that holds 10 int's and will set each element of the array to be 42.
The second constructor will take one argument, which will be an array of int. This constructor will create an instance array of the same size as the argument and then copy the integers from the argument to the instance array.
I have no idea how to even start on that.
Instance members are simply variables that belong to a class object, as long as it is not a static variable! A static variable, strictly speaking belongs to the class not an object, Constructors is just a special method you call to create and initialize an object. It is also the name of your class.
So what you want is
class WhateverYourClassIs
{
int[] members;
public WhateverYourClassIs()//constructor.
{
members = new int[10] ;
}
public WhateverYourClassIs(int n) //overloaded constructor.
{
members = new int[n] ;
}
}
So as you can see in the above example, constructors like methods, can be overloaded. By overloaded it means the signature is different. One constructor takes no argument, another takes a single argument that is an int.