In the code below is there any advantage/disadvantage/reason for creating the array in the constructor only i.e is there any difference between the two snippets of code below that I should be aware of?
Only in constructor.
public class multidimensionalarraysExp {
public multidimensionalarraysExp() {
int[][] intArray = new int[][]{{1, 2, 3},{4, 5, 6},{7, 8, 9}};
}
}
compared to this:
public class multidimensionalarraysExp {
private int[][] intArray;
public multidimensionalarraysExp() {
intArray = new int[][]{{1, 2, 3},{4, 5, 6},{7, 8, 9}};
}
}
I'm assuming it's because if I make it in the constructor I can't say whether it is public or private etc. So does this default to something?
Of course I could do this, but then why have a constructor in the first place?
public class multidimensionalarraysExp {
private intArray = new int[][]{{1, 2, 3},{4, 5, 6},{7, 8, 9}};
public multidimensionalarraysExp() {
}
}
Some basic questions but I don't see why a constructor is even needed.....