0

Why Animal constructor is not being called by the declaration of the array? LINE 12

Isn't 10 instances of Animal class is being created with this line?

package javaapplication;

class Animal
{
    Animal() { System.out.println("Animal Constructor");}
}

public class Main
{
    public static void main(String[] args)
    {        
        Animal[] animal_obj = new Animal[10];
    }
}
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by NormR1
0

Isn't 10 instances of Animal class is being created with this line?

Nope, ten uninitialized reference variables of type Animal are being created.

0

Creating an array only creates the array object. There are no Animal objects in it yet.
You need to fill the array with Animal objects, element by element.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.