Thinking in Java Fourth Edition Bruce Eckel Chapter 4 Exercise 7

Exercise 7: Create a class without a constructor, and then create an object of that class in main( ) to verify that the default constructor is automatically synthesized.

class Aso
{
    void bark()
    {
        System.out.println("woof");
    }
}  

public class AutomaticConstructor
{
    public static void main(String[] args)
    {
        Aso a = new Aso();
        a.bark();
    }
}

Output:

Leave a Reply

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