public class Dados{
int numeros[];
Dados(){
numeros = {1,2,3,4,5,6};
}
}
NetBeans marks me an error. How can I initialize the array in the constructor?
public class Dados{
int numeros[];
Dados(){
numeros = {1,2,3,4,5,6};
}
}
NetBeans marks me an error. How can I initialize the array in the constructor?
That type of initializer can only be used in the declaration of the variable.
int numeros[] = {1,2,3,4,5,6};
If you want to initialize the variable numeros
in the constructor you should do it like this:
Dados() {
numeros = new int[]{1,2,3,4,5,6};
}