The code below will not compile successfully unless the argument to the makeMenuItem method is final.Why not?
public JMenuItem makeMenuItem(final String menuLabel)
{
JMenuItem mi = new JMenuItem(menuLabel) ;
class MyMenuListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
doSomethingElse() ;
System.out.println(menuLabel) ;
}
}
mi.addActionListener(new MyMenuListener() ) ;
return mi;
}
A) JMenuItem labels must be final
B) This prevents the menuLabel argument from being modified
C) Because a local variable is being accessed from an inner classes
D) Because the String class is final
Correct Answer:
Verified
Q64: What code would be the most appropriate
Q65: What method is required by the ChangeListener
Q66: What type of event does the JSlider
Q67: Consider the scope of the three objects
Q68: The ChangeEvent class defines no methods.What makes
Q70: The event that is generated by a
Q71: What can you add action listeners to?
A)Menu
Q72: Which of the following statements is correct?
A)new
Q73: When method makeMenuItem is called, how many
Q74: If one ChangeListener is listening for three
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents