My Background is C++ and in c++ we can easily create array of object using simple syntax. className obj[n];
and also constructor will call n
time.
But When I tried to create array of object in java className[] obj=new className[n];
no constructor call. After searching I found the answer of this question on stackoverflow that it just create n
Reference that can point to n
objects and I need to create objects again for each reference like. obj[0]=new className();
Now I just want to ask why java do this? is there any reason even C++ allows but java not allows to create array of objects in same way? I searched for this but still didn't get exact answer.