Thinking in Java Fourth Edition Bruce Eckel Chapter 1 Exercise 3

Exercise 3: Find the code fragments involving ATypeName and turn them into  a program that compiles and runs.

Solution:

public class ATNTest
{      
    public static void main(String[] args)
    {
        class ATypeName
        {
            int i;
            double d;
            boolean b;
            void show()
            {
                System.out.println(i);
                System.out.println(d);
                System.out.println(b); 
            }
        }  
        ATypeName a = new ATypeName();
        a.i = 3;
        a.d = 2.71828;
        a.b = false;       
        a.show();
    }
}

Output:

Leave a Reply

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