SCJP考试题-2

来源:互联网 发布:翻译软件 win7 编辑:程序博客网 时间:2024/06/05 19:46
日志 > 软件编程
设置置顶 | 编辑 | 删除

SCJP考试题-2

发表于:2008年4月30日 13时53分46秒阅读(4)评论(0)本文链接:http://user.qzone.qq.com/169188811/blog/1209534826
QUESTION NO: 106
Exhibit:
1. public class X implements Runnable(
2. private int x;
3. private int y;
4.
5. public static void main(String[]args)
6. X that = new X();
7. (new Thread(that)).start();
8. (new Thread(that)).start();
9. )
10.
11. public void run() (
12. for (;;) (
13. x++;
14. y++;
15. System.out.printIn(“x=” + x + “, y = ” + y);
16. )
17. )
18. )
What is the result?
A. Errors at lines 7 and 8 cause compilation to fail.
B. The program prints pairs of values for x and y that might not always be the same on the same line
(for example, “x=2, y=1”).
C. The program prints pairs of values for x and y that are always the same on the same line (for
example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by
“x=1, y=1”).
D. The program prints pairs of values for x and y that are always the same on the same line (for
example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1”
followed by “x=2, y=2”).
Answer: D
QUESTION NO: 107
Given:
1. public class SyncTest {
2. private int x;
3. private int y;
4. public synchronized void setX (int i) (x=1;)
5. public synchronized void setY (int i) (y=1;)
6. public synchronized void setXY(int 1)(set X(i); setY(i);)
7. public synchronized Boolean check() (return x !=y;)
8. )
Under which conditions will check () return true when called from a different class?
A. Check() can never return true.
B. Check() can return true when setXY is called by multiple threads.
C. Check() can return true when multiple threads call setX and setY separately.
D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.
Answer: A
QUESTION NO: 108
Which is a method of the MouseMotionListener interface?
A. Public void mouseDragged(MouseEvent)
B. Public boolean mouseDragged(MouseEvent)
C. Public void mouseDragged(MouseMotionEvent)
D. Public boolean MouseDragged(MouseMotionEvent)
E. Public boolean mouseDragged(MouseMotionEvent)
Answer: A
QUESTION NO: 109
Given:
1. String foo = “base”;
2. foo.substring(0,3);
3. foo.concat(“ket”);
4. foo += “ball”;
5.
Type the value of foo at line 8.
Answer: BASEBALL
QUESTION NO 110
Given:
1. public class Test {
2. public static void leftshift(int i, int j) {
3. i<<=j;
4. }
5. public static void main(String args[]) {
6. int i = 4, j = 2;
7. leftshift(i, j);
8. System.out.printIn(i);
9. }
10. }
What is the result?
A. 2
B. 4
C. 8
D. 16
E. The code will not compile.
Answer: B
QUESTION NO 111
Given:
1. public class Foo {
2. private int val;
3. public foo(int v) (val = v;) }
4. public static void main (String [] args) {
5. Foo a = new Foo (10);
6. Foo b = new Foo (10);
7. Foo c = a;
8. int d = 10;
9. double e = 10.0;
10. }
11. }
Which three logical expression evaluate to true? (Choose Three)
A. (a ==c)
B. (d ==e)
C. (b ==d)
D. (a ==b)
E. (b ==c)
F. (d ==10.0)
Answer: A, B, F
QUESTION NO 112
Exhibit:
1. public class X {
2. private static int a;
3.
5. public static void main (String[] args) {
6. modify (a);
7. }
8.
9. public static void modify (int a) {
10. a++;
11. }
12. }
What is the result?
A. The program runs and prints “0”
B. The program runs and prints “1”
C. The program runs but aborts with an exception.
D. En error “possible undefined variable” at line 5 causes compilation to fail.
F. En error “possible undefined variable” at line 10 causes compilation to fail.
Answer: A
QUESTION NO 113
Exhibit:
1. public class Test {
2. public static void replaceJ(string text) {
3. text.replace (‘j’, ‘l’);
4. }
5.
6. public static void main(String args[]) {
7. string text = new String (“java”)
8. replaceJ(text);
9. system.out.printIn(text);
10. }
11. }
What is the result?
A. The program prints “lava”
B. The program prints “java”
C. An error at line 7 causes compilation to fail.
D. Compilation succeeds but the program throws an exception.
Answer: B
QUESTION NO 114
Which two are equivalent? (Choose Two)
A. 3/2
B. 3<2
C. 3*4
D. 3<<2
E. 3*2^2
F. 3<<<2
Answer: C, D
QUESTION NO 115
What is the numerical range of a char?
A. 0 . . . 32767
B. 0 . . . 65535
C. ?C256 . . . 255
D. ?C32768 . . . 32767
E. Range is platform dependent.
Answer: B
QUESTION NO 116
Given:
1. public class Test {
2. public static void main (String []args) {
3. unsigned byte b = 0;
4. b--;
5.
6. }
7. }
What is the value of b at line 5?
A. -1
B. 255
C. 127
D. Compilation will fail.
E. Compilation will succeed but the program will throw an exception at line 4.
Answer: D
QUESTION NO 117
Given:
1. public class Foo {
2. public void main (String [] args) {
3. system.out.printIn(“Hello World.”);
4. }
5. }
What is the result?
A. An exception is thrown.
B. The code does no compile.
C. “Hello World.” Is printed to the terminal.
D. The program exits without printing anything.
Answer: A
QUESTION NO 118
Given:
1. //point X
2. public class foo (
3. public static void main (String[]args) throws Exception {
4. java.io.printWriter out = new java.io.PrintWriter (
5. new java.io.outputStreamWriter (System.out), true;
6. out.printIn(“Hello”);
7. }
8. }
Which statement at PointX on line 1 allows this code to compile and run?
A. Import java.io.*;
B. Include java.io.*;
C. Import java.io.PrintWriter;
D. Include java.io.PrintWriter;
E. No statement is needed.
Answer: E
 
想第一个看到日志抢沙发?评论列表
请选择道具
<textarea class="content" id="commentEditor" style="BORDER-RIGHT: #ccc 1px solid; BORDER-TOP: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid; COLOR: gray! important; BORDER-BOTTOM: #ccc 1px solid" onfocus="getUBBeditor(this)" rows="13" cols="50" name="content">点击这里发表评论</textarea>
温馨提示:点击验证码输入框,以获取验证码
请输入验证码:
     
上一篇|下一篇|返回日志列表