📄 tt.html
字号:
<br><br>
4. }
<br><br>
<br><br>
5. public void itemStateChanged(ItemEvent ie) {
<br><br>
6. System.out.println("Item.");
<br><br>
7. }
<br><br>
8. }
<br><br>
<br><br>
a. The code compiles without error.
<br><br>
b. The code generates a compiler error at line 1.
<br><br>
c. The code generates a compiler error at line 2.
<br><br>
d. The code generates a compiler error at line 5.
<br><br>
<br><br>
Q25
<br><br>
A text field has a variable-width font. It is constructed by calling new TextField("iiiii"). What happens if you change the contents of the textfield to "wwwww"? (NOTE i is one of the narrowest characters, and w is one of the widest.)
<br><br>
<br><br>
a. The text field becomes wider.
<br><br>
b. The text field becomes narrower.
<br><br>
c. The text field stays the same width; to see the entire contents you have to scroll using -> and <-.
<br><br>
d. The text field stays the same width; to see you need to have a horizontal scroll bar.
<br><br>
<br><br>
Q26
<br><br>
Which statements about garbage collection are true? Select all valid answers
<br><br>
a. You can directly free the memory allocated by an object.
<br><br>
b. You can directly run the garbage collector whenever you want.
<br><br>
c. The garbage collector informs your object when it is about to be garbage collected.
<br><br>
d. The garbage collector runs in low-memory situations.
<br><br>
<br><br>
Q27
<br><br>
The setForeground() and setBackground() methods are defined in the following class
<br><br>
a. Graphics
<br><br>
b. Container
<br><br>
c. Component
<br><br>
d. Applet
<br><br>
<br><br>
Q28
<br><br>
What methods does JAVA define in the java.lang.Math class specifically for trigonometric calculations? Select all valid answers.
<br><br>
a. cos()
<br><br>
b. asin()
<br><br>
c. arctan()
<br><br>
d. sine()
<br><br>
Q29
<br><br>
Imagine that there are two exception classes called Exception1 and Exception2 that descend from the Exception class. Given these two class definitions,
<br><br>
<br><br>
1. class First {
<br><br>
2. void test() throws Exception1, Exception2 { . . . }
<br><br>
3. }
<br><br>
<br><br>
4. class Second extends First {
<br><br>
5. void test() { . . . }
<br><br>
<br><br>
Create a class called Third that extends Second and defines a test() method. What exceptions can Third's test method throw? Select all valid answers.
<br><br>
<br><br>
a. Exception1
<br><br>
b. Exception2
<br><br>
c. no checked exceptions
<br><br>
d. any exceptions declared in the throws clause of the Third's test() method.
<br><br>
<br><br>
Q30
<br><br>
Given these code snippets,
<br><br>
<br><br>
1. Boolean b1 = new Boolean(true);
<br><br>
2. Boolean b2 = new Boolean(true);
<br><br>
<br><br>
which expressions are legal JAVA expressions that return true? Select all valid answers.
<br><br>
a. b1 == b2
<br><br>
b. b1.equals(b2)
<br><br>
c. b1 & b2
<br><br>
d. b1 || b2
<br><br>
<br><br>
Q31
<br><br>
What will appear in the standard output when you run the Tester class?
<br><br>
<br><br>
1. class Tester {
<br><br>
2. int var;
<br><br>
<br><br>
3. Tester(double var) {
<br><br>
4. this.var = (int)var;
<br><br>
5. }
<br><br>
<br><br>
6. Tester(int var) {
<br><br>
7. this("hello");
<br><br>
8. }
<br><br>
<br><br>
9. Tester(String s) {
<br><br>
10. this();
<br><br>
11. System.out.println(s);
<br><br>
12. }
<br><br>
<br><br>
13. Tester() {
<br><br>
14. System.out.println("good-bye");
<br><br>
15. }
<br><br>
<br><br>
16. public static void main(String args[]) {
<br><br>
17. Tester t = new Tester(5);
<br><br>
18. }
<br><br>
<br><br>
a. "hello"
<br><br>
b. 5
<br><br>
c. "hello" followed by "good-bye"
<br><br>
d. "good-bye" followed by "hello"
<br><br>
<br><br>
Q32
<br><br>
What are the range of values for a variable of type short?
<br><br>
a. -2^7 to 2^7-1
<br><br>
b. 0 to 2^8
<br><br>
c. -2^15 to 2^15-1
<br><br>
d. -2^15-1 to 2^15
<br><br>
<br><br>
Q33
<br><br>
Analyze the following two classes
<br><br>
<br><br>
1. class First {
<br><br>
2. static int a = 3;
<br><br>
3. }
<br><br>
<br><br>
4. final class Second extends First {
<br><br>
5. void method() {
<br><br>
6. System.out.println(a);
<br><br>
7. }
<br><br>
8. }
<br><br>
<br><br>
a. Class First compiles, but class Second does not.
<br><br>
b. Neither class compiles.
<br><br>
c. Both classes compile, and if method() is invoked, it writes 3 to the output.
<br><br>
d. Both classes compile, and if method() is invoked, it throws an exception.
<br><br>
<br><br>
<br><br>
Q34
<br><br>
What String instance method would return true when invoked as follows?
<br><br>
<br><br>
1. a.method(b);
<br><br>
<br><br>
where a equals "GROUNDhog" and b equals "groundHOG"?
<br><br>
a. equals()
<br><br>
b. toLowerCase()
<br><br>
c. toUpperCase()
<br><br>
d. equalsIgnoreCase()
<br><br>
<br><br>
Q35
<br><br>
What access control keyword should you use to enable other classes to access a method freely within its package, but to restrict classes outside of the package from accessing that method? Select all valid answers.
<br><br>
<br><br>
a. private
<br><br>
b. public
<br><br>
c. protected
<br><br>
d. Do not supply an access control keyword (friendly).
<br><br>
<br><br>
Q36
<br><br>
What letters are written to the standard output with the following code?
<br><br>
<br><br>
1. class Unchecked {
<br><br>
2. public static void main(String args[]) {
<br><br>
3. try {
<br><br>
4. method();
<br><br>
5. } catch(Exception e) { }
<br><br>
6. }
<br><br>
<br><br>
7. static void method() {
<br><br>
8. try {
<br><br>
9. wrench();
<br><br>
10. System.out.println("a");
<br><br>
11. } catch(ArithmeticException e) {
<br><br>
12. System.out.println("b");
<br><br>
13. } finally {
<br><br>
14. System.out.println("c");
<br><br>
15. }
<br><br>
16. System.out.println("d");
<br><br>
17. }
<br><br>
<br><br>
18. static void wrench() {
<br><br>
19. throw new NullPointerException();
<br><br>
20. }
<br><br>
21. }
<br><br>
<br><br>
Select all valid answers.
<br><br>
a. "a"
<br><br>
b. "b"
<br><br>
c. "c"
<br><br>
d. "d"
<br><br>
<br><br>
Q37
<br><br>
If you would like to change the size of a Component, you can use the following method
<br><br>
a. size()
<br><br>
b. resize()
<br><br>
c. setSize()
<br><br>
d. dimension()
<br><br>
<br><br>
Q38
<br><br>
Which LayoutManager arranges components left to right and then top to bottom, centering each row as it moves to the next row?
<br><br>
a. BorderLayout
<br><br>
b. FlowLayout
<br><br>
c. GridLayout
<br><br>
d. CardLayout
<br><br>
<br><br>
Q39
<br><br>
Which label names(s) are illegal? Select all valid answers.
<br><br>
a. here
<br><br>
b. _there
<br><br>
c. this
<br><br>
d. 2to1odds
<br><br>
<br><br>
Q40
<br><br>
Which keyword, when used in front of a method, must also appear in front of the class.
<br><br>
a. synchronized
<br><br>
b. abstract
<br><br>
c. public
<br><br>
d. private
<br><br>
<br><br>
Q41
<br><br>
Given this code snippet,
<br><br>
<br><br>
1. try {
<br><br>
2. tryThis();
<br><br>
3. return;
<br><br>
4. } catch(IOException x1) {
<br><br>
5. System.out.println("exception 1");
<br><br>
6. return;
<br><br>
7. } catch(Exception x2) {
<br><br>
8. System.out.println("exception 2");
<br><br>
9. return;
<br><br>
10. } finally {
<br><br>
11. System.out.println("finally");
<br><br>
12. }
<br><br>
<br><br>
what will appear in the standard output if tryThis() throws a IOException?
<br><br>
a. "exception 1" followed by "finally"
<br><br>
b. "exception 2" followed by "finally"
<br><br>
c. "exception 1"
<br><br>
d. "exception 2"
<br><br>
<br><br>
<br><br>
Q42
<br><br>
Given the code snippet,
<br><br>
<br><br>
1. double a = 90.7;
<br><br>
2. double b = method(a);
<br><br>
3. System.out.println(b);
<br><br>
<br><br>
if this snippet displays 90.0 in the standard output, what Math method did method() invoke? Select all valid answers.
<br><br>
a. abs()
<br><br>
b. round()
<br><br>
c. floor()
<br><br>
d. ceil()
<br><br>
<br><br>
<br><br>
Q43
<br><br>
What is written to the standard output given the following statement
<br><br>
<br><br>
1. System.out.println(4 | 7);
<br><br>
a. 4
<br><br>
b. 5
<br><br>
c. 6
<br><br>
d. 7
<br><br>
<br><br>
Q44
<br><br>
What expressions are true concerning the following lines of code?
<br><br>
<br><br>
1. int[] arr = {1, 2, 3};
<br><br>
2. for(int i = 0 ; i < 2; i++)
<br><br>
3. arr[i] = 0;
<br><br>
<br><br>
Select all valid answers.
<br><br>
a. arr[0] == 0
<br><br>
b. arr[1] == 2
<br><br>
c. arr[1] == 0
<br><br>
d. arr[2] == 3
<br><br>
<br><br>
Q45
<br><br>
What will the following block of code write to standard output when it is executed?
<br><br>
<br><br>
1. int i = 3;
<br><br>
2. int j = 0;
<br><br>
3. double k = 3.2;
<br><br>
4. if (i < k)
<br><br>
5. if (i == j)
<br><br>
6. System.out.println(i);
<br><br>
7. else
<br><br>
8. System.out.println(j);
<br><br>
9. else
<br><br>
10. System.out.println(k);
<br><br>
<br><br>
a. 3
<br><br>
b. 0
<br><br>
c. 3.2
<br><br>
d. None of these.
<br><br>
<br><br>
Q46
<br><br>
What is the output of the following piece of code
<br><br>
1. int x = 6;
<br><br>
2. double d = 7.7;
<br><br>
<br><br>
3. System.out.println((x>d) ? 99.9 : 9);
<br><br>
a. 9
<br><br>
b. 9.0
<br><br>
c. 99.9
<br><br>
d. Nothing, an ArithmeticException is thrown at line 3.
<br><br>
<br><br>
Q47
<br><br>
Which of the following are legal methods for the String class ?
<br><br>
a. length()
<br><br>
b. toUpper()
<br><br>
c. toUppercase()
<br><br>
d. equals()
<br><br>
<br><br>
Q48
<br><br>
Consider the following
<br><br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -