A+ Answers
1. (TCOs 1–8) Suppose A is an interface and B is a concrete class with a default constructor that implements A. Which of the following is correct? (Points : 3)
B b = new B();
A a = new A();
B b = new A();
none of them
Question 2.2. (TCOs 1–8) Which of the following is a correct interface? (Points : 3)
abstract interface A { abstract void print({ };}
interface A { void print() { }; }
abstract interface A { print(); }
interface A { void print();}
Question 3.3. (TCOs 1–8) Which of the following statements will not convert a string s into i of int type? (Points : 3)
i = Integer.valueOf(s);
i = (new Integer(s)).intValue();
i = Integer.valueOf(s).intValue();
i = Integer.parseInt(s);
i = (int)(Double.parseDouble(s));
Question 4.4. (TCOs 1–8) Analyze the following code.
public class Test { // 1
public static void main(String[ ] args) { // 2
Fruit[ ] fruits = {new Fruit(2), new Fruit(3), new Fruit(1)}; // 3
java.util.Arrays.sort(fruits); // 4
} // 5
} // 6
class Fruit {
private double weight;
public Fruit(double weight) {
this.weight = weight;
}
} (Points : 3)
The program has a compile error because the Fruit class does not have a default constructor.
The program has a runtime error on Line 3 because the Fruit class does not have a default constructor.
The program has a runtime error on Line 4 because the Fruit class does not implement the java.lang.Comparable interface and the Fruit objects are not comparable.
The program has a compile error on Line 4 because the Fruit class does not implement the java.lang.Comparable interface and the Fruit objects are not comparable.
Question 5.5. (TCOs 1–8) Analyze the following code.
import java.util.*; // 1
public class Test { // 2
public static void main(String[ ] args) { // 3
Calendar[ ] calendars = new Calendar[10]; // 4
calendars[0] = new Calendar(); // 5
calendars[1] = new GregorianCalendar(); // 6
} // 7
} // 8 (Points : 3)
The program has a compile error on Line 4 because java.util.Calendar is an abstract class.
The program has no compile errors.
The program has a compile error on Line 6 because Calendar[1] is not of a GregorianCalendar type.
The program has a compile error on Line 5 because java.util.Calendar is an abstract class.
Question 6.6. (TCOs 1–8) Suppose A is an anonymous inner class in Test. A is compiled into a file named _____ (Points : 3)
A.class.
Test$1.class.
A$Test.class.
Test$A.class.
Test&1.class.
Question 7.7. (TCOs 1–8) You cannot use getWhen() to find the time of an _____ (Points : 3)
KeyEvent.
WindowEvent.
ActionEvent.
MouseEvent.
Question 8.8. (TCOs 1–8) Which of the following statement is false? (Points : 3)
You can add multiple listeners for a Timer object.
To start a timer, invoke timer.start().
To stop a timer, invoke timer.stop().
When a timer is created, it is automatically started.
You must always specify a listener when creating a Timer object.
Question 9.9. (TCOs 1–8) To be a listener for ActionEvent, an object must be an instance of _____ (Points : 3)
WindowEvent.
EventObject.
WindowListener.
ActionEvent.
ActionListener.
Question 10.10. (TCOs 1–8) What is the value of evt.getKeyCode() or evt.getChar() for the keyTyped() events? (Points : 3)
VK_UNDEFINED
The Unicode code of the character
The ASCII code of the character
A character