Multiple Choice
How do the lifetimes of the three objects menuLabel, mi, and the anonymous object new MyMenuListener() compare? public JMenuItem makeMenuItem(final String menuLabel)
{
JMenuItem mi = new JMenuItem(menuLabel) ;
Class MyMenuListener implements ActionListener
{
Public void actionPerformed(ActionEvent
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
E) {
DoSomethingElse() ;
System.out.println(menuLabel) ;
}
}
Mi) addActionListener(new MyMenuListener() ) ;
Return mi;
}
Correct Answer:

Verified
Correct Answer:
Verified
Q8: When adding a component to a container
Q21: What is the easiest way to create
Q22: _ are round and have a black
Q24: For a new programmer using the Swing
Q25: When method makeMenuItem is called, how many
Q27: Which layout manager may change the location
Q29: When a menu item is selected, what
Q30: What is the container for top-level menu
Q30: Suppose a JPanel with a BorderLayout manager
Q31: Which component can be added to a