?? mockcert07.txt
字號:
top.add(new Checkbox("Cbox"));
f.add(top, BorderLayout.NORTH);
Panel left = new Panel();
left.setLayout(new GridLayout(1, 2));
left.add(new Scrollbar(Scrollbar.VERTICAL));
left.add(new Button("Button"));
f.add(left, BorderLayout.WEST);
f.setVisible(true);
}
}
Only One:
1) The checkbox
2) The scrollbar
3) The button
4) The "top" panel
5) The "left" panel
Question 21
===========================================================
What is the result of attempting to compile the following code?
1. class OutThing {
2.
3. class AnInner {
4. public int i;
5. }
6.
7. public static void main(String[] args) {
8. AnInner aninn = new AnInner();
9. aninn.i = 15;
10. }
11. }
Only One:
1) he code compiles without error.
2) Compiler error on line 4.
3) Compiler error on line 8.
4) Compiler error on line 9.
Question 22
===========================================================
When application A below is run, two threads are created and started. Each thread prints a message just before terminating. Which thread prints its message first?
class A {
private Thread t1, t2;
public static void main(String[] args) {
new A();
}
A() {
t1 = new T1();
t2 = new T2();
t1.start();
t2.start();
}
class T1 extends Thread {
public void run() {
try {
sleep(5000); // 5 secs
}
catch (InterruptedException e) { }
System.out.println("t1 done");
}
}
class T2 extends Thread {
public void run() {
try {
t1.sleep(10000); // 10 secs
}
catch (InterruptedException e) { }
System.out.println("t2 done");
}
}
}
Only One:
1) t1
2) t2
Question 23
===========================================================
If a Java program imports a large number of classes, what is the runtime impact?
Only One:
1) There is no impact at runtime.
2) There is a slight impact at runtime.
3) There is a moderate impact at runtime.
4) There is a significant impact at runtime.
Question 24
===========================================================
Which of the lines below are printed out by the following application?
1. import java.io.IOException;
2. class SubEx extends IOException { }
3.
4. class A {
5. public static void main(String[] args) {
6. try {
7. thud();
8. }
9. catch (SubEx x) {
10. System.out.println("main() caught SubEx");
11. }
12. catch (IOException x) {
13. System.out.println(
14. "main() caught IOException");
15. }
16. catch (Exception x) {
17. System.out.println(
18. "main() caught Exception");
19. }
20. }
21.
22. static void thud() throws IOException {
23. try {
24. throw new SubEx();
25. }
26. catch (SubEx x) {
27. System.out.println("thud() caught SubEx");
28. throw new IOException();
29. }
30. catch (IOException x) {
31. System.out.println(
32. "thud() caught IOException");
33. throw new IOException();
34. }
35. catch (Exception x){
36. System.out.println(
37. "thud() caught Exception");
38. }
39. }
40. }
Mutiple:
1) "main() caught SubEx"
2) "main() caught IOException"
3) "main() caught Exception"
4) "thud() caught SubEx"
5) "thud() caught IOException"
Question 25
===========================================================
What happens when you attempt to compile the following code?
1. class A { static void foo(int i) {}; }
2. class B extends A { void foo(int i) {}; }
Only One:
1) Compiler error at line 1.
2) Compiler error at line 2.
3) No compiler error.
Question 26
===========================================================
Consider the following class definition:
class Parent {
void abcde(int i) throws IOException {
if (i > 10) throw new IOException();
}
}
Which of the following methods would be allowed in a subclass of Parent?
Mutiple:
1) protected void abcde(int i) throws IOException
2) private void abcde(int i) throws IOException
3) void abcde(int j) throws IOException
4) float abcde(int i) throws IOException
5) void abcde(int i)
Question 27
===========================================================
What is the value of the following expression?
Math.round(Math.random() + 2.50001);
Only One:
1) 2
2) 3
3) It is impossible to say.
Question 28
===========================================================
What one statement is true about the following code?
1. Map map = new HashMap();
2. map.put("key", "Hello");
3. map.put("key", "Goodbye");
Only One:
1) Line 3 generates a compiler error.
2) An exception is thrown at line 3.
3) After line 3 executes, the map contains one entry: the string "Hello".
4) After line 3 executes, the map contains one entry: the string "Goodbye".
5) After line 3 executes, the map contains two entries.
Question 29
===========================================================
A computer is manufactured and shipped to Tibet. When the computer's operating system is installed, it is told that it is in the Tibet locale. When the computer executes the following line, what encoding is used by the File Reader?
FileReader fr = new FileReader("8859_1");
Only One:
1) Tibetan
2) US ASCII
Question 30
===========================================================
What happens when you try to compile and execute the following application? (Choose all that apply.)
1. class Switcheroo {
2. public static void main(String[] args) {
3. long i = 0;
4. try {
5. i = Integer.parseInt(args[0]);
6. }
7. catch (Exception e) { }
8.
9. switch (i) {
10. case 0:
11. System.out.println("zero");
12. case 1:
13. System.out.println("one");
14. default:
15. System.out.println("default");
16. }
17. }
18. }
Only One:
1) Compiler error.
2) The program prints "zero".
3) The program prints "one".
4) he program prints "default"
Question 31
===========================================================
Which of the following statements are true?
Mutiple:
1) You can directly read text from a FileReader.
2) You can directly write text to a FileWriter.
3) You can directly read ints and floats from a FileReader.
4) You can directly write longs and shorts to a FileWriter.
5) You can directly read text from a RandomAccessFileReader.
Question 32
===========================================================
In the code listed below, how many key-value pairs are contained in the map after line 6 executes?
1. Map map = new HashMap();
2. map.put("1", "1");
3. map.put("2", "2");
4. map.put("3", "3");
5. map.put("1", "3");
6. map.put("4", "1");
Only One:
1) 1
2) 2
3) 3
4) 4
5) 5
Question 33
===========================================================
If a superclass and a subclass are in two different packages, can the subclass override a protected method of the superclass?
Only One:
1) Yes
2) No
Question 34
===========================================================
Which of the following code fragments throw ArithmeticException?
Mutiple:
1) int i = 1; i = i << 32;
2) int i = 1; i = i >> 1;
3) int i = 1; i = i >>> 1;
4) int i = 1; int j = i >>> 1; int k = i / j;
5) int i = 0x7FFF; i *= 5;
Question 35
===========================================================
Does the code below compile?
1. class SubEx extends Exception { }
2.
3. class Parent {
4. void foo(int i) throws Exception {
5. if (i > 20)
6. throw new Exception();
7. }
8. }
9.
10. class Kid extends Parent {
11. void foo(int i) throws SubEx {
12. if (i < 20)
13. throw new SubEx();
14. }
15. }
Only One:
1) Yes
2) No
Question 36
===========================================================
Consider the following code:
1. interface Inter { }
2. class A { }
3. class B extends A implements Inter { }
4. class C extends B {
5. public static void main(String[] args) {
6. A a = new A();
7. B b = new B();
8. C c = new C();
9. if (a instanceof B)
10. System.out.println("Hello");
11. if (b instanceof A)
12. System.out.println("Hello");
13. if (c instanceof C)
14. System.out.println("Hello");
15. if (c instanceof Inter)
16. System.out.println("Hello");
17. }
18. }
When you run class C as an application, which of the following lines execute?
Mutiple:
1) Line 10
2) Line 12
3) Line 14
4) Line 16
Question 37
===========================================================
True or false: It is legal to instantiate a class that contains abstract methods, provided you do not call any of those abstract methods.
Only One:
1) True
2) False
Question 38
===========================================================
What happens when you try to compile the following code and execute the Dolphin application?
1. class Animal { }
2. class Mammal extends Animal { }
3. class Cat extends Mammal { }
4. class Dolphin extends Mammal {
5. public static void main(String[] args) {
6. Mammal m = new Cat();
7. Animal a = m;
8. Dolphin d = (Dolphin)a;
9. }
10. }
Mutiple:
1) The code compiles without error but throws an exception at line 8.
2) The code compiles without error but throws an exception at line 7.
3) The code compiles without error but throws an exception at line 6.
4) The code compiles with no errors and runs without throwing any exceptions.
Question 39
===========================================================
How many String objects exist as a result of running the code listed below?
1. String s1 = "abc";
2. String s2 = s1;
3. String s3 = "abc";
Only One:
1) None
2) 1
3) 2
4) 3
Question 40
===========================================================
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -