I want to create an array of class objects and initialize it also without using any method so i wrote code like this:
package test;
public class Test2 {
private Test2() {
}
static Test2[] arr = new Test2[10];
static {
for (Test2 ob : arr) {
ob = new Test2();
}
for (Test2 ob : arr) {
System.out.println(ob);
}
}
public static void main(String args[]) {
}
}
But when i run this program, i get o/p:
null
null
null
null
....
Why is it happening? It seems that constructor is not called when i create a new object