Hi, I am reading a passage in Java book that goes like this:
class TimePrinter implements ActionListener { public void actionPerformed(ActionEvent event) { Date now = new Date(); System.out.println("At the tone, the time is " + now); Toolkit.getDefaultToolkit().beep(); } }
Now to use TimePrinter we would do:
ActionListener listener = new TimePrinter(); Timer timer = new Timer(20000, listener);
I am confuse about creating awhen 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?new TimePrinter();