Thinking in Java Fourth Edition Bruce Eckel Chapter 4 Exercise 17

 Exercise 17: Create a class with a constructor that takes a String argument. During construction, print the argument. Create an array of object references to this class, but don’t actually create objects to assign into the array. When you run the program, notice whether the initialization messages from the constructor calls are printed.

class InitTest
{
    InitTest(String s)
    {
        System.out.println("InitTest()");
        System.out.println(s);
    }
}

public class InitTest17
{
    public static void main(String[] args)
    {
        InitTest[] it = new InitTest[10];
    }
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *