Thinking in Java Fourth Edition Bruce Eckel Chapter 4 Exercise 1

Exercise 1: Create a class containing an uninitialized String reference. Demonstrate that this reference is initialized by Java to null.

class Tester
{
    String s;
}

public class ConstructorTest
{
    public static void main(String[] args)
    {
        Tester t = new Tester();
        System.out.println(t.s);
    }
}

Output:

Leave a Reply

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