Which of the following corrects defines a ButtonListener as an inner class and c
ID: 3847567 • Letter: W
Question
Which of the following corrects defines a ButtonListener as an inner class and creates an instance of ButtonListener as a listener for the button? class ButtonListener implements ActionListener { public void actionPerformed (AnEvent event) { System.out.println("Button clicked"); } } button.addActionListener (new ButtonListener ()); class ButtonListener implements ActionEvent { public void actionPerformed (ActionListener event) { System. out.println ("Button clicked"); } } ActionListener listener = new ButtonListener (); button.addActionListener (listener); class ButtonListener implements ActionListener { public void actionPerformed (ActionEvent event) { System.out.println ("Button clicked"); } } ActionListener listener = new ButtonListener (); listener.actionPerformed (event); class ButtonListener implements ActionListener { public void actionPerformed (ActionEvent event) { System.out.println ("Button clicked"); } } button. addActionListener(new ButtonListener ()); Using the given definition of the Measurable interface: public interface Measurable { double getMeasure(); } Consider the following code snippet, assuming that BankAccount has a getBalance method and implements the Measurable interface by providing an implementation for the getMeasure method: Measurable m = new BankAccount (); System.out.println(m.getBalance ()); Which of the following statements is true? The code does not compile because a variable of type Measurable does not have a getBalance method. The code compiles but generates an exception at run time because a Measurable object reference does not have a getBalance method. The code executes, displaying the balance of the bank account. The code does not compile because you cannot assign a BankAccount object to a variable of type Measurable. Which of the following is the correct class header for a MouseclickListener class that wants to take advantage of the do-nothing methods provided by the MouseAdapter class? class MouseClickListener implements MouseAdapter class MouseClickListener extends MouseAdapter interface MouseClickListener extends MouseAdapter class MouseClick Listener implements MouseListenerExplanation / Answer
(1) The answer is option (d)
class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent event)
{
System.out.println("Button Clicked");
}
}
button.addActionListener(new ButtonListener());
(2) The answer is option (a)
The code does not compile because a variable of type Measurable does not have a getBalance method
(3) The answer is:
class MouseClickListener extends MouseAdapter
This is because, both MouseClickListener and MouseAdapter are classes. And one class can only be extended from the other class, but not implemented.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.