Consider the scope of the three objects menuLabel, mi, and the anonymous object new MyMenuListener() within the JmenuItem class.How do thier lifetimes compare?
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) all have the same lifetimes
B) menuLabel and new MyMenuListener() are the same and both longer than mi
C) mi and new MyMenuListener() are the same and both longer than menuLabel
D) from shortest to longest:menuLabel, new MyMenuListener() , mi
Correct Answer:
Verified
Q62: What is the general order of a
Q63: Which code will create a JSlider with
Q64: What code would be the most appropriate
Q65: What method is required by the ChangeListener
Q66: What type of event does the JSlider
Q68: The ChangeEvent class defines no methods.What makes
Q69: The code below will not compile successfully
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
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