★★★ 难题求解!请帮忙! ★★★ (能写几个就写几个吧)
Question 19)
You are browsing the Java HTML documentation for information on the java.awt.TextField component. You want to create Listener
code to respond to focus events. The only Listener method listed is addActionListener. How do you go about finding out about
Listener methods.
1) Define your own Listener interface according to the event to be tracked
2) Use the search facility in the HTML documentation for the listener needed
3) Move up the hierarchy in the HTML documentation to locate methods in base
classes
4) Subclass awt.event with the appropriate Listener method
Question 21:)4
In the following code fragment from an applet, we know that the getParameter call may return a null if there is no parameter
named size. Which logical operator should replace X in line 5 to ensure that a NullPointerException is not generated if tmp
is null.
1. int sz;
2. public void init(){
3. sz=10;
4. String tmp=getParameter("size");
5. if(tmp!=null X tmp.equals("BIG")) sz=20;
6. }
a). Replace X with '&'
b). Replace X with '&&'
c). Replace X with '|'
d). Replace X with '||'
Question 23: [Check all correct answers] )bcd
You are writing a java class in a file named "MyClass.java", this class must be accessible by all classes in a large project.
Which of the following would be correct class declarations?
a. private class MyClass extends Object
b. class myclass extends Object
c. public class MyClass
d. public class MyClass extends Object
Question 24: [Check all correct answers]
Once created, some Java objects are "immutable", meaning they can not have their contents changed. Which of the following
classed produce immutable objects?
a. java.lang.Double
b. java.lang.StringBuffer
c. java.lang.Boolean
d. java.lang.Math
41.容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变?
A CardLayout
B FlowLayout
C BorderLayout
D GridLayout
Question 46: Given the following class definition:
class A {
protected int i;
A(int i) {
this.i = i;
}
}
Which of the following would be a valid inner class for this class?
Select all valid answers.
a)
class B {
}
b)
class B extends A {
}
c)
class B {
B() {
System.out.println("i = " + i);
}
}
d)
class B {
class A {
}
}
e)
class A {
}
Question47: What statements are true concerning the method notify() that is used in conjunction with wait()? d
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
c) notify() is defined in the Thread class
d) it is not strictly necessary to own the lock for the object you invoke notify() for
e) notify() should only be invoked from within a while loop
Question 52: 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);
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();