Hello,
can I initialize an instance variable in Java, when I initialise it when I declare it, and initialise it with the return value of a method, which I define later in the class. Something like this:
public class MyClass {
integers[] myArray = new integers[length()];
int length() {
....
}
}
length() gives me some number, and I want this number to determine the number of elements in the array. It seems plausible to me, but I get NullPointerException (I don't know whether this mistake initialization is causing the exception, but I don't know what exactly, and because I have never done this initialization before, I am not sure it is correct). Thank you.