Exam Prep Practice Questions

Question 1 You need to write code in an applet that will call the submitData method when button1 is clicked. To do this, use addActionListener to connect button1 with an object that implements the ActionListener interface. The only method in this interface has this signature:
void actionPerformed( ActionEvent e );

Which of the following anonymous class declarations is the correct way to do this?

  • A.

    button1.addActionListener(
           new ActionListener()
           { public void
               actionPerformed( ActionEvent evt )
             {  submitData() ;
             }
           }
         );
    
  • B.

    button1.addActionListener(
           new Object implements ActionListener()
           { public void
               actionPerformed( ActionEvent evt )
             {  submitData() ;
             }
           }
         );
    
  • C.

     button1.addActionListener( new ActionListener() { submitData() ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.