Consider the following interface (comments omitted):
public interface MouseListener extends EventListener {
void mouseClicked(MouseEvent event);
void mousePressed(MouseEvent event);
void mouseReleased(MouseEvent event);
void mouseEntered(MouseEvent event);
void mouseExited(MouseEvent event);
}
Assume you extend the interface to handle some mouse events for your application, so that you have the following:
// Context omitted
private class MyMouseListener implements MouseListener {
void mouseClicked(MouseEvent event) {
// handle mouse click here
}
}
As it turned out, MyMouseListener cannot be used the way it is. What is the problem?
- The "extends" keyword needs to be used instead of "implements" in line "private class MyMouseListener implements MouseListener".
- Classes cannot be private in Java.
- The mouseClicked method should not return a value.