Next question is how the parameter "this" refers the ActionListener only? Why not your own program object ButtonDemo, or a Frame or ActionEvent?
You are right cent percent to think so. Then how to answer the above question. For the answer, we must refer the method signature of addActionListener() method as defined in Button class. Following is the one.
public synchronized void addActionListener(ActionListener);
Observe, the parameter must be an object of ActionListener. When we pass "this" to addActionListener() method, the JVM tries to convert "this" into an object of ActionListener because the method demands it. The JVM finds it, in the class declaration, after implements keyword and simply links btn to ActionListener. To have a proof, just remove "implements ActionListener" and compile the program, the program does not compile.
The whole process can be put diagrammatically as follows.
This type of event handling mechanism designed by the designers follows "Observer design pattern". The ActionListener observes always the button when it gets clicked. This type of event handling model is known as "delegation event model". In this model, responsibility of event handling is delegated (assigned) to listeners.