Thinking in Java Fourth Edition Bruce Eckel Chapter 4 Exercise 18

Exercise 18: Complete the previous exercise by creating objects to attach to the array of references.

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

public class InitTest18
{
    public static void main(String[] args)
    {
        InitTest[] it = new InitTest[5];
        for(int i = 0; i < it.length; i++)
            it[i] = new InitTest(Integer.toString(i));
    }
}

Output:

Leave a Reply

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