Assume that you are defining a class and you want to implement an ActionListener. You state addActionListener(this); in your class’ constructor. What does this mean?

Assume that you are defining a class and you want to implement an ActionListener.  You state addActionListener(this); in your class’ constructor.  What does this mean?

a)       The class must import another class which implements ActionListener
b)       The class must define the method actionPerformed
c)       The class must define the method ActionListener
d)       The class must define an inner class called ActionListener
e)       The class must define the method actionPerformed in an inner class named ActionListener


Answer:  b.

Explanation:  Since the ActionListener being implemented is being added in this class (that is what the “this” refers to in addActionListener), then this class must define the abstract methods of the ActionListener class.  There is only one abstract method, actionPerformed.  The answer in a is not true, if the class that implements ActionListener were being imported (assume that the variable al is an instance of this imported class), then the proper statement would be addActionListener(al);.


Enhancing Classes

Learn More Multiple Choice Question :