⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mockcert06.txt

📁 一道JAVA方面的试题 很不错的 我很喜欢
💻 TXT
📖 第 1 页 / 共 5 页
字号:
 1. class Greebo extends java.util.Vector
 2.   implements Runnable {
 3.     public void run(String message) {
 4.       System.out.println("in run() method: " +
 5.       message);
 6.   }
 7. }
 8.
 9. class GreeboTest {
10.   public static void main(String args[]) {
12.     Greebo g = new Greebo();
13.     Thread t = new Thread(g);
14.     t.start();
15.   }
16. }

Only One: 
1) There will be a compiler error, because class Greebo does not correctly implement the Runnable interface.
2) There will be a compiler error at line 13, because you cannot pass a parameter to the constructor of a Thread.
3) The code will compile correctly but will crash with an exception at line 13.
4) The code will compile correctly but will crash with an exception at line 14.
5) The code will compile correctly and will execute without throwing any exceptions.


Question 60
===========================================================
Which one statement below is always true about the following application?

 1. class HiPri extends Thread {
 2.   HiPri() {
 3.     setPriority(10);
 4.   }
 5.
 6.   public void run() {
 7.     System.out.println(
 8.       "Another thread starting up.");
 9.     while (true) { }
10.   }
11.
12.   public static void main(String args[]) {
13.     HiPri hp1 = new HiPri();
14.     HiPri hp2 = new HiPri();
15.     HiPri hp3 = new HiPri();
16.     hp1.start();
17.     hp2.start();
18.     hp3.start();
19.   }
20. }

Only One: 
1) When the application is run, thread hp1 will execute; threads hp2 and hp3 will never get the CPU.
2) When the application is run, all three threads (hp1, hp2, and hp3) will get to execute, taking time-sliced turns in the CPU.
3) Either A or B will be true, depending on the underlying platform.


Question 61
===========================================================
True or false: A thread wants to make a second thread ineligible for execution. To do this, the first thread can call the yield() method on the second thread.

Only One: 
1) True
2) False


Question 62
===========================================================
A thread's run() method includes the following lines:

1. try {
2.   sleep(100);
3. } catch (InterruptedException e) { }
Assuming the thread is not interrupted, which one of the following statements is correct?

Only One: 
1) The code will not compile, because exceptions may not be caught in a thread's run() method.
2) At line 2, the thread will stop running. Execution will resume in, at most, 100 milliseconds.
3) At line 2, the thread will stop running. It will resume running in exactly 100 milliseconds.
4) At line 2, the thread will stop running. It will resume running some time after 100 milliseconds have elapsed.


Question 63
===========================================================
A monitor called mon has 10 threads in its waiting pool; all these waiting threads have the same priority. One of the threads is thr1. How can you notify thr1 so that it alone moves from the Waiting state to the Ready state?

Only One: 
1) Execute notify(thr1); from within synchronized code of mon.
2) Execute mon.notify(thr1); from synchronized code of any object.
3) Execute thr1.notify(); from synchronized code of any object.
4) Execute thr1.notify(); from any code (synchronized or not) of any object.
5) You cannot specify which thread will get notified.


Question 64
===========================================================
If you attempt to compile and execute the application listed below, will it ever print out the message In xxx?

 1. class TestThread3 extends Thread {
 2.   public void run() {
 3.     System.out.println("Running");
 4.     System.out.println("Done");
 5.   }
 6.
 7.  private void xxx() {
 8.    System.out.println("In xxx");
 9.  }
10.
11.   public static void main(String args[]) {
12.     TestThread3 ttt = new TestThread3();
13.     ttt.xxx();
14.     ttt.start();
12.   }
13. }

Only One: 
1) Yes
2) No


Question 65
===========================================================
True or false: A Java monitor must either extend Thread or implement Runnable.

Only One: 
1) True
2) False


Question 66
===========================================================
Given a string constructed by calling s = new String("xyzzy"), which of the calls listed below modify the string? (Choose all that apply.)

Only One: 
1) s.trim();
2) s.substring(3);
3) s.replace(`z', `a');
4) s.concat(s);
5) None of the above


Question 67
===========================================================
Which one statement is true about the code below?

1. String s1 = "abc" + "def";
2. String s2 = new String(s1);
3. if (s1 == s2)
4.   System.out.println("== succeeded");
5. if (s1.equals(s2))
6.   System.out.println(".equals() succeeded");

Only One: 
1) Lines 4 and 6 both execute.
2) Line 4 executes, and line 6 does not.
3) Line 6 executes, and line 4 does not.
4) Neither line 4 nor line 6 executes.


Question 68
===========================================================
Suppose you want to write a class that offers static methods to compute hyperbolic trigonometric functions. You decide to subclass java.lang.Math and provide the new functionality as a set of static methods. Which one statement below is true about this strategy?

Only One: 
1) The strategy works.
2) The strategy works, provided the new methods are public.
3) The strategy works, provided the new methods are not private.
4) The strategy fails, because you cannot subclass java.lang.Math.
5) The strategy fails, because you cannot add static methods to a subclass.


Question 69
===========================================================
Which one statement is true about the code fragment below?

1. import java.lang.Math;
2. Math myMath = new Math();
3. System.out.println("cosine of 0.123 = " + 
4.   myMath.cos(0.123));

Only One: 
1) Compilation fails at line 2.
2) Compilation fails at line 3 or 4.
3) Compilation succeeds, although the import on line 1 is not necessary. During execution, an exception is thrown at line 3 or 4.
4) Compilation succeeds. The import on line 1 is necessary. During execution, an exception is thrown at line 3 or 4.
5) Compilation succeeds, and no exception is thrown during execution.


Question 70
===========================================================
Which one statement is true about the code fragment below?

1. String s = "abcde";
2. StringBuffer s1 = new StringBuffer("abcde");
3. if (s.equals(s1))
4.   s1 = null;
5. if (s1.equals(s))
6.   s = null;

Only One: 
1) Compilation fails at line 1, because the String constructor must be called explicitly.
2) Compilation fails at line 3, because s and s1 have different types.
3) Compilation succeeds. During execution, an exception is thrown at line 3.
4) Compilation succeeds. During execution, an exception is thrown at line 5.
5) Compilation succeeds. No exception is thrown during execution.


Question 71
===========================================================
True or false: In the code fragment below, after execution of line 1, sbuf references an instance of the StringBuffer class. After execution of line 2, sbuf still references the same instance.

1. StringBuffer sbuf = new StringBuffer("abcde");
2. sbuf.insert(3, "xyz");

Only One: 
1) True
2) False


Question 72
===========================================================
True or false: In the code fragment below, after execution of line 1, sbuf references an instance of the StringBuffer class. After execution of line 2, sbuf still references the same instance.

1. StringBuffer sbuf = new StringBuffer("abcde");
2. sbuf.append("xyz");

Only One: 
1) True
2) False


Question 73
===========================================================
True or false: In the code fragment below, line 4 is executed.

1. String s1 = "xyz";
2. String s2 = "xyz";
3. if (s1 == s2)
4.   System.out.println("Line 4");

Only One: 
1) True
2) False


Question 74
===========================================================
True or false: In the code fragment below, line 4 is executed.

1. String s1 = "xyz";
2. String s2 = new String(s1);
3. if (s1 == s2)
4.   System.out.println("Line 4");

Only One: 
1) True
2) False


Question 75
===========================================================
Which would be most suitable for storing data elements that must not appear in the store more than once, if searching is not a priority?

Only One: 
1) Collection
2) List
3) Set
4) Map
5) Vector


Question 76
===========================================================
A Java program creates a check box using the code listed below. The program is run on two different platforms. Which of the statements following the code are true? (Choose one or more.)

1. Checkbox cb = new Checkbox("Autosave");
2. Font f = new Font("Courier", Font.PLAIN, 14);
3. cb.setFont(f);

Mutiple: 
1) The check box will be the same size on both platforms, because Courier is a standard Java font.
2) The check box will be the same size on both platforms, because Courier is a fixed-width font.
3) The check box will be the same size on both platforms, provided both platforms have identical 14-point plain Courier fonts.
4) The check box will be the same size on both platforms, provided both platforms have identical check-box decorations.
5) There is no way to guarantee that the check boxes will be the same size on both platforms.


Question 77
===========================================================
What is the result of attempting to compile and execute the following application under JDK 1.2 or later?

 1. import java.awt.*;
 2.
 3. public class Q2 extends Frame {
 4.   Q2() {
 5.     setSize(300, 300);
 6.     Button b = new Button("Apply");
 7.     add(b);
 8.   }
 9.
10.   public static void main(String args[]) {
11.     Q2 that = new Q2();
12.     that.setVisible(true);
13.   }
14. }

Only One: 
1) There is a compiler error at line 11, because the constructor on line 4 is not public.
2) The program compiles but crashes with an exception at line 7, because the frame has no layout manager.
3) The program displays an empty frame.
4) The program displays the button, using the default font for the button label. The button is just large enough to encompass its label.
5) The program displays the button, using the default font for the button label. The button occupies the entire frame.


Question 78
===========================================================
What is the result of compiling and running the following application?

 1. import java.awt.*;
 2.
 3. public class Q3 extends Frame {
 4.   Q3() {
 5.     // Use Grid layout manager.
 6.     setSize(300, 300);
 7.     setLayout(new GridLayout(1, 2));
 8.
 9.     // Build and add 1st panel.
10.     Panel p1 = new Panel();
11.     p1.setLayout(
12.       new FlowLayout(FlowLayout.RIGHT));
13.     p1.add(new Button("Hello"));
14.     add(p1);
15.
16.     // Build and add 2nd panel.
17.     Panel p2 = new Panel();
18.     p2.setLayout(
19.       new FlowLayout(FlowLayout.LEFT));
20.     p2.add(new Button("Goodbye"));
21.     add(p2);
22.   }
23.
24.   public static void main(String args[]) {
25.     Q3 that = new Q3();
26.     that.setVisible(true);
27.   }
28. }

Only One: 
1) The program crashes with an exception at line 7, because the frame's default layout manager cannot be overridden.
2) The program crashes with an exception at line 7, because a Grid layout manager must have at least two rows and two columns.
3) The program displays two buttons, which are just large enough to encompass their labels. The buttons appear at the top of the frame. The "Hello" button is just to the left of the vertical midline of the frame; the "Goodbye" button is just to the right of the vertical midline of the frame.
4) The program displays two large buttons. The "Hello" button occupies the entire left half of the frame, and the "Goodbye" button occupies the entire right half of the frame.
5) The program displays two buttons, which are just wide enough to encompass their labels. The buttons are as tall as the frame. The "Hello" button is just to the left of the vertical midline of the frame; the "Goodbye" button is just to the right of the vertical midline of the frame.


Question 79
===========================================================
Please select correct answer:

Only One: 
1) Each button is as wide as the frame and is just tall enough to encompass its label. The "Alpha" button is at the top of the frame. The "Beta" button is in the middle. The "Gamma" button is at the bottom.
2) Each button is as wide as the frame. The "Alpha" button is at the top of the frame and is just tall enough to encompass its label. The "Beta" button is in the middle of the frame; its height is approximately one-third the height of the frame. The "Gamma" button is at the bottom of the frame and is just tall enough to encompass its label.
3) Each button is just wide enough and just tall enough to encompass its label. All three buttons are centered horizontally. The "Alpha" button is at the top of the frame. The "Beta" button is in the middle. The "Gamma" button is at the bottom.
4) Each button is just wide enough to encompass its label. All three buttons are centered horizontally. The "Alpha" button is at the top of the frame and is just tall enough to encompass its label. The "Beta" button is in the middle of the frame; its height is approximately one-third the height of the frame. The "Gamma" button is at the bottom of the frame and is just tall enough to encompass its label.
5) Each button is as tall as the frame and is just wide enough to encompass its label. The "Alpha" button is at the left of the frame. The "Beta" button is in the middle. The "Gamma" button is at the right.


Question 80
===========================================================
You would like to compile and execute the following code. After the frame appears on the screen (assuming you get that far), you would like to resize the frame to be approximately twice its original width and approximately twice its original height. Which of the statements following the code is correct? (Choose one.)

 1. import java.awt.*;
 2.
 3. public class Q5 extends Frame {
 4.   Q5() {
 5.     setSize(300, 300);
 6.     setFont(new Font("SanSerif", Font.BOLD, 36));
 7.     Button b = new Button("Abracadabra");
 8.     add(b, BorderLayout.SOUTH);
 9.   }
10.
11.   public static void main(String args[]) {
12.     Q5 that = new Q5();
13.     that.setVisible(true);
14.   }
15. }

Only One: 
1) Compilation fails at line 8, because the frame has not been given a layout manager.
2) Before resizing, the button appears at the top of the frame and is as wide as the frame. After resizing, the button retains its original width and is still at the top of the frame.
3) Before resizing, the button appears at the bottom of the frame and is as wide as the frame. After resizing, the button retains its original width and is the same distance from the top of the frame as it was before resizing.
4) Before resizing, the button appears at the bottom of the frame and is as wide as the frame. After resizing, the button is as wide as the frame's new width and is still at the bottom of the frame.
5) Before resizing, the button appears at the bottom of the frame and is as wide as the frame. After resizing, the button retains its original width and is about twice as tall as it used to be. It is still at the bottom of the frame.


Question 81
===========================================================
The following code builds a GUI with a single button. Which one statement is true about the button's size?

 1. import java.awt.*;
 2.
 3. public class Q6 extends Frame {
 4.   Q6() {
 5.     setSize(500, 500);
 6.     setLayout(new FlowLayout());
 7.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -