试题由单选题和多选题组成,单选题将提示:Select the one right answer.,多选题将提示:Select all valid answers.。
Select all valid answers.
Question 2: What statements are true concerning the method notify() that is used in conjunction with wait()?
Select all valid answers.
a) if there is more than one thread waiting on a condition, only the thread that has been waiting the longest is notified
b) if there is more than one thread waiting on a condition,there is no way to predict which thread will be notifed
d) it is not strictly necessary to own the lock for the object you invoke notify() for
Select all valid answers.
共10页: 1 [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页
[
public void run() {
try {
for (int i = 1; i <= 100; i++) {
System.out.println(i);
Thread.sleep(1000);
}
} catch (InterruptedException x) {}
}
}
--------------------------------------------------------------------------------
Question 6: Given the following class definition:
class A {
public int x;
private int y;
class B {
protected void method1() {
}
class C {
private void method2() {
}
}
}
}
class D extends A {
public float z;
}
What can method2() access directly, without a reference to another instance?
Select all valid answers.
a) the variable x defined in A
b) the variable y defined in A
c) method1 defined in B
d) the variable z defined in D
--------------------------------------------------------------------------------
Question 7: You have an 8-bit file using the character set defined by ISO 8859-8. You are writing an application to display this file in a TextArea. The local encoding is already set to 8859-8. How can you write a chunk of code to read the first line from this file?
You have three variables accessible to you:
myfile is the name of the file you want to read
stream is an InputStream object associated with this file
s is a String object
Select all valid answers.
a)
InputStreamReader reader = new InputStreamReader(stream, "8859-8");
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
b)
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
c)
InputStreamReader reader = new InputStreamReader(myfile, "8859-8");
BufferedReader buffer = new BufferedReader(reader);
共10页: 上一页 [1] [2] 3 [4] [5] [6] [7] [8] [9] [10] 下一页
[
s = buffer.readLine();
d)
InputStreamReader reader = new InputStreamReader(myfile);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
e)
FileReader reader = new FileReader(myfile);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
--------------------------------------------------------------------------------
Question 8: How can you write a line of code for an applet’s init() method that determines how wide the applet is?
Select all valid answers.
a) int width = this.getY();
b) int width = this.getSize().w;
c) int width = getSize();
d) int width = getSize().w;
e) int width = getWidth();
--------------------------------------------------------------------------------
Question 9: For a variable width font, how "wide" is a TextField created using the expression:
new TextField(20)
Select the one right answer.
a) 20 times the average of all the characters in the font used for this TextField object
b) 20 times the width of the letter M
c) 20 times the width of the letter a
d) 20 inches
e) 20 picas
--------------------------------------------------------------------------------
Question 10: Given this interface definition:
interface A {
int method1(int i);
int method2(int j);
}
which of the following classes implement this interface and is not abstract?
Select all valid answers.
a)
class B implements A {
int method1() { }
int method2() { }
}
b)
class B {
int method1(int i) { }
int method2(int j) { }
}
c)
class B implements A {
int method1(int i) { }
int method2(int j) { }
}
d)
class B extends A {
int method1(int i) { }
int method2(int j) { }
}
e)
class B implements A {
int method2(int j) { }
int method1(int i) { }
}
--------------------------------------------------------------------------------
Question 11: Given the following code:
import java.awt.*;
import java.awt.event.*;
public class MyApplet extends java.applet.Applet {
public void init() {
Button b = new Button("Button1");
b.addMouseListener(new ClickHandler());
共10页: 上一页 [1] [2] [3] 4 [5] [6] [7] [8] [9] [10] 下一页
[
add(b);
}
class ClickHandler extends MouseAdapter {
public void mouseClicked(MouseEvent evt) {
// A
}
}
}
What line of code at A writes the mouse’s horizontal location to the standard output at the time of the event?
Fill in the blank.
--------------------------------------------------------------------------------
Question 12: Given the same code as in question 10, how can you write a line of code at A that will place the Button object into a variable named mybutton that is already defined to be a reference to a Button object?
Fill in the blank.
--------------------------------------------------------------------------------
Question 13: Which Listener interface can you implement to be able to respond to the user hitting the enter key after typing into a TextField object?
Fill in the blank.
--------------------------------------------------------------------------------
Question 14: What is written to the standard output as the result of executing the following statements?
Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(true);
if (b1 == b2)
if (b1.equals(b2))
System.out.println("a");
else
System.out.println("b");
else
if (b1.equals(b2))
System.out.println("c");
else
System.out.println("d");
Select the one right answer.
a) a
b) b
c) c
d) d
-------------------------
[1] [2] [3] 下一页