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
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.
A constructor is the part of a class which generates instances of that class. It's named the same thing as the class and has no return type. For example:
An instance field is a variable local to each instance of the class. You can either have public, protected, or private instance fields. A private instance field is "hidden" from the outside world and only the instance itself can access it. A public one is accessed using the
.
operator. For example:public class Foo{ public int x; private int y; }
For your case, you'll want
Here you overload the constructors (just like for methods) and create an array, which is a list of, in this case,
int
s of a fixed length.