Array Construction

Can anyone explain why the constructor doesn't get called when I create an array of objects of class Ex4. I've learnt from books that in Java the constructor gets called whenever memory is allocated for an object using new.

public class Ex4

{

Ex4()

{

System.out.println("Called Ex4 Constructor!!!");

}

public static void main(String[] args)

{

Ex4[] arr = new Ex4[5];

}

}

[446 byte] By [prabu_sa] at [2007-11-27 9:43:37]
# 1

Ex4[] arr = new Ex4[5];

Because the above line creates an array. It doesn't automagically create 5 objects for you and stick them in the array.

I want to pick some apples but before I do that I need to build a box that can hold them. After I have built the box, how many apples are in the box?

floundera at 2007-7-12 23:49:15 > top of Java-index,Java Essentials,New To Java...
# 2
Hi flounder, Thanks for your help. The concept is clear to me now.
prabu_sa at 2007-7-12 23:49:15 > top of Java-index,Java Essentials,New To Java...