Construct a class that implement ActionListener with no constructor
Hi, I am reading a passage in Java book that goes like this:
Now to use TimePrinter we would do:
ActionListener listener = new TimePrinter();
Timer timer = new Timer(20000, listener);
I am confuse about creating a when the TimePrinter class have no constructor. From what I read, if a class have no constructor, it will then call the superclass of TimePrinter, which is Object, and use the default no-arg constructor. But I think its a bit confusing for me to create a class without constructor but only a method. Can somebody lighten me up on this a little bit more?
Re: Construct a class that implement ActionListener with no constructor
In Java, if you have no explicitly defined constructor, there's a default constructor which initializes all values to their "default" value, i.e. nulls, 0's, etc. This is what's known as a an implicit constructor. Note that once you provide even 1 constructor for the class, you no longer get the implicit constructor.