Solved

The Code Below Will Not Compile Successfully Unless the Argument

Question 59

Multiple Choice

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:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions