Thinking in Java Fourth Edition Bruce Eckel Chapter 6 Exercise 3

Exercise 3: Prove the previous sentence.

Statement: Even if you don’t create a constructor for Cartoon(), the compiler will synthesize a default constructor for you that calls the base-class constructor.

class Art
{
    Art()
    {
        System.out.println("Art constructor");
    }
}

class Drawing extends Art
{
    Drawing()
    {
        System.out.println("Drawing constructor");
    }
}

public class Cartoon2 extends Drawing
{
    public static void main(String[] args)
    {
        Cartoon2 x = new Cartoon2();
    }
}

Output:

Leave a Reply

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