在main函数中实例化内部类时会报错:
No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).
说没有可用的实例,代码:
public class Test {
public static void main(String[] args){
TimePinter listener = new TimePinter();
Timer timer = new Timer(10000, listener);
JOptionPane.showConfirmDialog(null, "Quit program");
<span style="white-space:pre"> </span>System.exit(0);
}
class TimePinter implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
Date now = new Date();
System.out.println("The current time is "+now);
Toolkit.getDefaultToolkit().beep();
}
}
}