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; }
Blog
Consider the following code snippet: public class Vehicle {…
Consider the following code snippet: public class Vehicle { . . . public void setVehicleClass(double numberAxles) { . . . } } public class Auto extends Vehicle { . . . public void setVehicleClass(int numberAxles) { . . . } } Which of the following statements is correct?
Consider the following code snippet: public class MyMouseL…
Consider the following code snippet: public class MyMouseListener { public void mousePressed(MouseEvent event) { double x; double y; _______ System.out.println(“x: ” + x + “, y: ” + y); } } Which of the following statements should be in the indicated position to print out where the mouse was pressed?
The _______ interface toolkit has a large set of user-interf…
The _______ interface toolkit has a large set of user-interface components.
Consider the following code snippet: public class MyMouseL…
Consider the following code snippet: public class MyMouseListener { public void mousePressed(MouseEvent event) { double x; double y; _______ System.out.println(“x: ” + x + “, y: ” + y); } } Which of the following statements should be in the indicated position to print out where the mouse was pressed?
Assume you are using a doubly-linked list data structure wit…
Assume you are using a doubly-linked list data structure with many nodes. What is the minimum number of node references that are required to be modified to remove a node from the middle of the list? Consider the neighboring nodes.
Assume you are using a doubly-linked list data structure wit…
Assume you are using a doubly-linked list data structure with many nodes. What is the minimum number of node references that are required to be modified to remove a node from the middle of the list? Consider the neighboring nodes.
Consider the following class hierarchy: public class Vehicle…
Consider the following class hierarchy: public class Vehicle { private String type; public Vehicle(String type) { this.type = type; } public String displayInfo() { return type; } } public class LandVehicle extends Vehicle { public LandVehicle(String type) { super(type); } } public class Auto extends LandVehicle { public Auto(String type) { super(type); } } You have written a program to use these classes, as shown in the following code snippet: public class VehicleTester { public static void main(String[] args) { Auto myAuto = new Auto(“sedan”); System.out.println(“MyAuto type = ” + ______); } } Complete the code in this program snippet to correctly display the auto’s type.
Select an appropriate expression to complete the following m…
Select an appropriate expression to complete the following method, which is designed to return the number of elements in the parameter array numbers. If a value appears more than once, it should be counted exactly once. public static int countElementsOnce(int[] numbers) { Set values = new HashSet(); for (int num: numbers) { values.add(num); } ______________________ }
Consider the following class hierarchy: public class Vehicle…
Consider the following class hierarchy: public class Vehicle { private String type; public Vehicle(String type) { this.type = type; } public String displayInfo() { return type; } } public class LandVehicle extends Vehicle { public LandVehicle(String type) { super(type); } } public class Auto extends LandVehicle { public Auto(String type) { super(type); } } You have written a program to use these classes, as shown in the following code snippet: public class VehicleTester { public static void main(String[] args) { Auto myAuto = new Auto(“sedan”); System.out.println(“MyAuto type = ” + ______); } } Complete the code in this program snippet to correctly display the auto’s type.