Which of the following are true about the "default" constructor? Select 2 correct options (1) It is provided by the compiler only if the class does not define any constructor (2) It initializes the instance members of the class (3) It calls the default 'no-args' constructor of the super class (4) It initializes instance as well as class fields of the class (5) It is provided by the compiler if the class does not define a 'no- args' constructor
An anonymous inner class doesnt have a constructor...only instance initializer
Yes it does - only you can't define any.
Consider this case:
There is a constructor, that takes a String. There are even constructors that take an Icon, or a String and an Icon, or any other constructor AbstractAction has. As for anonymous classes implementing interfaces (new ActionListener() ...), there is also a constructor - a non-arg constructor.
(2) It initializes the instance members of the class ... my doubt is why not 2 is correct .....
Seems two books I checked agree with you: From Core Java (J2SE 5.0) , Volume I, Page 128
If you write a class with no constructors whatsoever, then a default constructor is provided for you. This default constructor sets all the instance fields to their default values. So, all numeric data contained in the instance fields would be 0, all Booleans would be false, and all object variables would be set to null.
From K&B 1.4. Page 314 when they discuss constructor chaining they also say:
5. Object constructor completes 6. Animal instance variables are given their explicit values (if any) 7. Animal constructor completes
Where did you get the question from? Do they provide any answer?
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop