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

📄 mockcert07.txt

📁 一道JAVA方面的试题 很不错的 我很喜欢
💻 TXT
📖 第 1 页 / 共 5 页
字号:
Question 1
===========================================================
In the code fragment below, what are the legal data types for the variable "answer"? 
byte  b = 1;
char  c = 2;
short s = 3;
int   i = 4;
float f = 5f;
answer = b * c * s * i * f;

Mutiple: 
1) char
2) short
3) int
4) float
5) double


Question 2
===========================================================
What does the following code print out? 
1. try {
2.   int i = -5 % -3;
3.   System.out.println("i = " + i);
4. }
5. catch (Exception e) {
6.   System.out.println("TROUBLE");
7. }

Only One: 
1) i = 2
2) i = 3
3) i = -2
4) i = -3
5) TROUBLE


Question 3
===========================================================
When you run the following application, which component is responsible for painting the pixel at the extreme bottom-right of the interior of the frame? 
import java.awt.*;
class A {
  private final static String[] regions = {
    BorderLayout.NORTH, BorderLayout.WEST,
    BorderLayout.SOUTH, BorderLayout.EAST,
    BorderLayout.CENTER
  };

  public static void main(String[] args) {
    Frame f = new Frame();
    f.setSize(800, 800);
    for (int i=0; i < regions.length; i++) {
      Scrollbar s =
        new Scrollbar(Scrollbar.HORIZONTAL);
      f.add(s, regions[i]);
    }
    f.setVisible(true);
  }
}

Only One: 
1) The scrollbar at North
2) The scrollbar at South
3) The scrollbar at East
4) The scrollbar at West
5) he scrollbar at Center


Question 4
===========================================================
Which of the following statements are true?

Mutiple: 
1) The RandomAccessFile class does not provide a method that positions the file's file pointer.
2) The RandomAccessFile class provides a method that positions the file's file pointer relative to the beginning of the file.
3) The RandomAccessFile class provides a method that positions the file's file pointer relative to the current file pointer position.
4) The RandomAccessFile class provides a method that positions the file's file pointer relative to the end of the file.


Question 5
===========================================================
Pick all the true statements below.

Mutiple: 
1) If a thread wants to call wait() on an object, the thread must own that object's lock.
2) There is a method that you can call on an instance of the Thread class that puts the instance to sleep for a specified number of milliseconds.
3) At the moment when a thread is notified, it automatically gets the lock of the object for which it was waiting.


Question 6
===========================================================
In the code fragment below, what is the value of k after line 3 executes? 
1. int i = -1;
2. int j = i >> 3;
3. int k = j & 129;

Only One: 
1) -1
2) 0
3) 129
4) A very large negative number
5) A very large positive number


Question 7
===========================================================
What happens when you attempt to compile and execute the following application? 
 1. class XXX {
 2.   public static void main(String[] args) {
 3.     String s1 = "abcde";
 4.     String s2 = "abcde";
 5.     s1.toUpperCase();
 6.     if (s1 == s2)
 7.       System.out.println("YES");
 8.     else
 9.       System.out.println("NO");
10.   }
11. }

Only One: 
1) Compiler error.
2) The program prints out "YES".
3) The program prints out "NO".


Question 8
===========================================================
In the code below, does line 7 compile? 
 1.  class Outside {
 2.    private final float i = 1.23f;
 3.
 4.    void amethod(float j) {
 5.      class Inside {
 6.        void innerFoo() {
 7.          float k = i + j;
 8.          System.out.println("k = " + k);
 9.        }
10.     }
11.   }
12. }

Only One: 
1) Yes
2) No


Question 9
===========================================================
What statement or statements below are true concerning the following code? 
 1. class X {
 2.   public static void main(String[] a) {
 3.     try {
 4.       short s = 0x00FD;
 5.       byte b = (byte)s;
 6.       System.out.println("b = " + b);
 7.     }
 8.     catch (Exception e) {
 9.       System.out.println("TROUBLE!");
10.     }
11.   }
12. }

Mutiple: 
1) It generates a compiler error at line 5.
2) If the cast on line 5 were omitted, then line 5 would not compile.
3) The code compiles and prints "b = 0".
4) The code compiles and prints "b = -2".
5) The code compiles and prints "b = -3".


Question 10
===========================================================
What happens when you run the following application? 
 1. class Q extends Thread {
 2.   public void run() {
 3.     for (int i = 0; i < 1000; i++)
 4.       System.out.println(i);
 5.   }
 6.
 7.   public static void main(String[] args) {
 8.     Q that = new Q();
 9.     that.run();
10.     for (int j = 999; j >= 0; j--)
11.       System.out.println(j);
12.   }
13. }

Only One: 
1) The code concurrently counts up to 999 and down from 999.
2) The code first counts up to 999, and then counts down from 999.
3) The code first counts down from 999, and then counts up to 999.


Question 11
===========================================================
When you run the following application, which component is responsible for painting the pixel at the center of the interior of the frame? 
import java.awt.*;
class A {
  public static void main(String[] args) {
    Frame f = new Frame();
    f.setSize(801, 801);
    Scrollbar sbar1 =
      new Scrollbar(Scrollbar.VERTICAL);
    f.add(sbar1, BorderLayout.WEST);
    Scrollbar sbar2 =
      new Scrollbar(Scrollbar.HORIZONTAL);
    f.add(sbar2, BorderLayout.NORTH);
    Button btn = new Button("PushMe");
    f.add(btn, BorderLayout.CENTER);
    f.setVisible(true);
  }
}

Only One: 
1) The horizontal scrollbar
2) The vertical scrollbar
3) The button


Question 12
===========================================================
What happens when you attempt to compile the following code? 
1. class Xyz {
2.   protected String toString() {
3.     return super.toString();
4.   }
5. }

Only One: 
1) Compiler error at line 2.
2) Compiler error at line 3.
3) No compiler error.


Question 13
===========================================================
What is the effect of attempting to compile the following code and then execute the Child application? 
 1. public class Papa {
 2.   int i;
 3.   Papa(int j) { i = j; }
 4. }
 5.
 6. class Child extends Papa {
 7.   Child() { i = 5; }
 8.   public static void main(String[] args) {
 9.     new Child();
10.   }
11. }

Only One: 
1) Compiler error at line 6.
2) Compiler error at line 7.
3) Compiler error at line 9.
4) The code compiles but throws an exception when the application is executed.
5) The code compiles and executes with no problems.


Question 14
===========================================================
What is the result of attempting to compile and execute the following application? 
1. public class X {
2.   public static void main(String[] args) {
3.     int i = Math.ceil(-Math.PI);
4.     System.out.println("i = " + i);
5.   }
6. }

Mutiple: 
1) Compiler error at line 3.
2) The code compiles, and prints out a value of 3.
3) The code compiles, and prints out a value of 4.
4) The code compiles, and prints out a value of -3.
5) The code compiles, and prints out a value of -4.


Question 15
===========================================================
Which statement or statements below is/are true about the following code, when run as an application? 
 1. class X {
 2.   public static void main(String[] args) {
 3.     try {
 4.       int i = (-1 >> 65535) + 1;
 5.       int j = 5 / i;
 6.       System.out.println("End of try block");
 7.     }
 8.   catch (Exception e) { System.exit(0); }
 9.   finally { System.out.println("FINALLY!"); }
10.   }
11. }

Mutiple: 
1) The program doesn't print anything.
2) The program prints "End of try block".
3) The program prints "FINALLY".


Question 16
===========================================================
Does the following code compile? If not, where is the first compiler error? 
1. interface Inter { }
2.
3. class A implements Inter { }
4.
5. class B extends A {
6.   A a = new B();
7.   Inter i = a;
8. }

Only One: 
1) The code compiles without error.
2) Compiler error at line 6.
3) Compiler error at line 7.


Question 17
===========================================================
Which of the following code fragments generate compiler errors?

Mutiple: 
1) boolean boo = true; int i = boo;
2) byte b = 5; char c = b;
3) char c1 = 'a'; short s = c1;
4) long lon = 1L; float f = lon;
5) float f1 = 2L; long lon1 = f1;


Question 18
===========================================================
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 (IOException x) {
10.       System.out.println(
11.         "main() caught IOException");
12.     }
13.     catch (Exception x) {
14.       System.out.println(
15.         "main() caught Exception");
16.     }
17.   }
18.
19.   static void thud() throws IOException {
20.     try {
21.       throw new SubEx();
22.     }
23.     catch (IOException x) {
24.       System.out.println(
25.         "thud() caught IOException");
26.       throw new SubEx();
27.     }
28.     catch (Exception x){
29.       System.out.println(
30.         "thud() caught Exception");
31.     }
32.   }
33. }

Mutiple: 
1) "main() caught IOException"
2) "main() caught Exception"
3) "thud() caught IOException"
4) "thud() caught Exception"


Question 19
===========================================================
True or false: All methods in all event listener interfaces in the java.awt.event package have the same return type.

Only One: 
1) True
2) False


Question 20
===========================================================
The following application displays a frame that contains several components. Which component is responsible for painting the top-left pixel of the frame's interior? 
import java.awt.*;
class A {
  public static void main(String[] args) {
    Frame f = new Frame();
    f.setSize(600, 300);
    Panel top = new Panel();
    top.setLayout(new FlowLayout(FlowLayout.RIGHT));

⌨️ 快捷键说明

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