📄 中文java技术网scjp考试题310-025(第二套4)91-147-147.htm
字号:
F. Java.util.Collection<br />
Answer: B, D<br />
QUESTION NO: 105<br />
Which statement is true for the class java.util.ArrayList?<br />
A. The elements in the collection are ordered.<br />
B. The collection is guaranteed to be immutable.<br />
C. The elements in the collection are guaranteed to be unique.<br />
D. The elements in the collection are accessed using a unique key.<br />
E. The elements in the collections are guaranteed to be synchronized.<br />
Answer: A<br />
QUESTION NO: 106<br />
Exhibit:<br />
1. public class X implements Runnable(<br />
2. private int x;<br />
3. private int y;<br />
4.<br />
5. public static void main(String[]args)<br />
6. X that = new X();<br />
7. (new Thread(that)).start();<br />
8. (new Thread(that)).start();<br />
9. )<br />
10.<br />
11. public void run() (<br />
12. for (;;) (<br />
13. x++;<br />
14. y++;<br />
15. System.out.printIn(“x=” + x + “, y = ” + y);<br />
16. )<br />
17. )<br />
18. )<br />
What is the result?<br />
A. Errors at lines 7 and 8 cause compilation to fail.<br />
B. The program prints pairs of values for x and y that might not always be the same on the same line<br />
(for example, “x=2, y=1”).<br />
C. The program prints pairs of values for x and y that are always the same on the same line (for<br />
example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by<br />
“x=1, y=1”).<br />
D. The program prints pairs of values for x and y that are always the same on the same line (for<br />
example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1”<br />
followed by “x=2, y=2”).<br />
Answer: D<br />
QUESTION NO: 107<br />
Given:<br />
1. public class SyncTest {<br />
2. private int x;<br />
3. private int y;<br />
4. public synchronized void setX (int i) (x=1;)<br />
5. public synchronized void setY (int i) (y=1;)<br />
6. public synchronized void setXY(int 1)(set X(i); setY(i);)<br />
7. public synchronized Boolean check() (return x !=y;)<br />
8. )<br />
Under which conditions will check () return true when called from a different class?<br />
A. Check() can never return true.<br />
B. Check() can return true when setXY is called by multiple threads.<br />
C. Check() can return true when multiple threads call setX and setY separately.<br />
D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.<br />
Answer: A<br />
QUESTION NO: 108<br />
Which is a method of the MouseMotionListener interface?<br />
A. Public void mouseDragged(MouseEvent)<br />
B. Public boolean mouseDragged(MouseEvent)<br />
C. Public void mouseDragged(MouseMotionEvent)<br />
D. Public boolean MouseDragged(MouseMotionEvent)<br />
E. Public boolean mouseDragged(MouseMotionEvent)<br />
Answer: A<br />
QUESTION NO: 109<br />
Given:<br />
1. String foo = “base”;<br />
2. foo.substring(0,3);<br />
3. foo.concat(“ket”);<br />
4. foo += “ball”;<br />
5.<br />
Type the value of foo at line 8.<br />
Answer: BASEBALL<br />
QUESTION NO 110<br />
Given:<br />
1. public class Test {<br />
2. public static void leftshift(int i, int j) {<br />
3. i<<=j;<br />
4. }<br />
5. public static void main(String args[]) {<br />
6. int i = 4, j = 2;<br />
7. leftshift(i, j);<br />
8. System.out.printIn(i);<br />
9. }<br />
10. }<br />
What is the result?<br />
A. 2<br />
B. 4<br />
C. 8<br />
D. 16<br />
E. The code will not compile.<br />
Answer: B<br />
QUESTION NO 111<br />
Given:<br />
1. public class Foo {<br />
2. private int val;<br />
3. public foo(int v) (val = v;) }<br />
4. public static void main (String [] args) {<br />
5. Foo a = new Foo (10);<br />
6. Foo b = new Foo (10);<br />
7. Foo c = a;<br />
8. int d = 10;<br />
9. double e = 10.0;<br />
10. }<br />
11. }<br />
Which three logical expression evaluate to true? (Choose Three)<br />
A. (a ==c)<br />
B. (d ==e)<br />
C. (b ==d)<br />
D. (a ==b)<br />
E. (b ==c)<br />
F. (d ==10.0)<br />
Answer: A, B, F<br />
QUESTION NO 112<br />
Exhibit:<br />
1. public class X {<br />
2. private static int a;<br />
3.<br />
5. public static void main (String[] args) {<br />
6. modify (a);<br />
7. }<br />
8.<br />
9. public static void modify (int a) {<br />
10. a++;<br />
11. }<br />
12. }<br />
What is the result?<br />
A. The program runs and prints “0”<br />
B. The program runs and prints “1”<br />
C. The program runs but aborts with an exception.<br />
D. En error “possible undefined variable” at line 5 causes compilation to fail.<br />
F. En error “possible undefined variable” at line 10 causes compilation to fail.<br />
Answer: A<br />
QUESTION NO 113<br />
Exhibit:<br />
1. public class Test {<br />
2. public static void replaceJ(string text) {<br />
3. text.replace (‘j’, ‘l’);<br />
4. }<br />
5.<br />
6. public static void main(String args[]) {<br />
7. string text = new String (“java”)<br />
8. replaceJ(text);<br />
9. system.out.printIn(text);<br />
10. }<br />
11. }<br />
What is the result?<br />
A. The program prints “lava”<br />
B. The program prints “java”<br />
C. An error at line 7 causes compilation to fail.<br />
D. Compilation succeeds but the program throws an exception.<br />
Answer: B<br />
QUESTION NO 114<br />
Which two are equivalent? (Choose Two)<br />
A. 3/2<br />
B. 3<2<br />
C. 3*4<br />
D. 3<<2<br />
E. 3*2^2<br />
F. 3<<<2<br />
Answer: C, D<br />
QUESTION NO 115<br />
What is the numerical range of a char?<br />
A. 0 . . . 32767<br />
B. 0 . . . 65535<br />
C. –256 . . . 255<br />
D. –32768 . . . 32767<br />
E. Range is platform dependent.<br />
Answer: B<br />
QUESTION NO 116<br />
Given:<br />
1. public class Test {<br />
2. public static void main (String []args) {<br />
3. unsigned byte b = 0;<br />
4. b--;<br />
5.<br />
6. }<br />
7. }<br />
What is the value of b at line 5?<br />
A. -1<br />
B. 255<br />
C. 127<br />
D. Compilation will fail.<br />
E. Compilation will succeed but the program will throw an exception at line 4.<br />
Answer: D<br />
QUESTION NO 117<br />
Given:<br />
1. public class Foo {<br />
2. public void main (String [] args) {<br />
3. system.out.printIn(“Hello World.”);<br />
4. }<br />
5. }<br />
What is the result?<br />
A. An exception is thrown.<br />
B. The code does no compile.<br />
C. “Hello World.” Is printed to the terminal.<br />
D. The program exits without printing anything.<br />
Answer: A<br />
QUESTION NO 118<br />
Given:<br />
1. //point X<br />
2. public class foo (<br />
3. public static void main (String[]args) throws Exception {<br />
4. java.io.printWriter out = new java.io.PrintWriter (<br />
5. new java.io.outputStreamWriter (System.out), true;<br />
6. out.printIn(“Hello”);<br />
7. }<br />
8. }<br />
Which statement at PointX on line 1 allows this code to compile and run?<br />
A. Import java.io.*;<br />
B. Include java.io.*;<br />
C. Import java.io.PrintWriter;<br />
D. Include java.io.PrintWriter;<br />
E. No statement is needed.<br />
Answer: E<br />
QUESTION NO 119<br />
Which will declare a method that is available to all members of the same package and can be referenced<br />
without an instance of the class?<br />
A. Abstract public void methoda();<br />
B. Public abstract double methoda();<br />
C. Static void methoda(double d1){}<br />
D. Public native double methoda() {}<br />
E. Protected void methoda(double d1) {}<br />
Answer: C<br />
QUESTION NO 120<br />
Which type of event indicates a key pressed on a java.awt.Component?<br />
A. KeyEvent<br />
B. KeyDownEvent<br />
C. KeyPressEvent<br />
D. KeyTypedEvent<br />
E. KeyPressedEvent<br />
Answer: A<br />
QUESTION NO 121<br />
Exhibit:<br />
1. import java.awt.*;<br />
2.<br />
3. public class X extends Frame {<br />
4. public static void main (String [] args) {<br />
5. X x = new X();<br />
6. x.pack();<br />
7. x.setVisible(true);<br />
8. }<br />
9.<br />
10. public X() {<br />
11. setLayout (new BordrLayout());<br />
12. Panel p = new Panel ();<br />
13. add(p, BorderLayout.NORTH);<br />
14. Button b = new Button (“North”);<br />
15. p.add(b):<br />
16. Button b = new Button (“South”);<br />
17. add(b1, BorderLayout.SOUTH):<br />
18. }<br />
19. }<br />
Which two statements are true? (Choose Two)<br />
A. The buttons labeled “North” and “South” will have the same width.<br />
B. The buttons labeled “North” and “South” will have the same height.<br />
C. The height of the button labeled “North” can very if the Frame is resized.<br />
D. The height of the button labeled “South” can very if the Frame is resized.<br />
E. The width of the button labeled “North” is constant even if the Frame is resized.<br />
F. The width of the button labeled “South” is constant even if the Frame is resized.<br />
Answer: B, E<br />
QUESTION NO 122<br />
How can you create a listener class that receives events when the mouse is moved?<br />
A. By extending MouseListener.<br />
B. By implementing MouseListener.<br />
C. By extending MouseMotionListener.<br />
D. By implementing MouseMotionListener.<br />
E. Either by extending MouseMotionListener or extending MouseListener.<br />
F. Either by implementing MouseMotion Listener or implementing MouseListener.<br />
Answer: D<br />
QUESTION NO 123<br />
Which statement is true?<br />
A. A grid bag layout can position components such that they span multiple rows and/or columns.<br />
B. The “North” region of a border layout is the proper place to locate a menuBar component in a<br />
Frame.<br />
C. Components in a grid bag layout may either resize with their cell, or remain centered in that cell at<br />
their preferred size.<br />
D. A border layout can be used to position a component that should maintain a constant size even<br />
when the container is resized.<br />
Answer: A<br />
QUESTION NO 124<br />
You want a class to have access to members of another class in the same package. Which is the most<br />
restrictive access modifier that will accomplish that will accomplish this objective?<br />
A. Public<br />
B. Private<br />
C. Protected<br />
D. Transient<br />
E. No access modifier is required.<br />
Answer: E<br />
QUESTION NO 125<br />
Which two statements are true regarding the creation of a default constructor? (Choose Two)<br />
A. The default constructor initializes method variables.<br />
B. The default constructor invokes the no-parameter constructor of the superclass.<br />
C. The default constructor initializes the instance variables declared in the class.<br />
D. If a class lacks a no-parameter constructor,, but has other constructors, the compiler creates a<br />
default constructor.<br />
E. The compiler creates a default constructor only when there are no other constructors for the class.<br />
Answer: C, E<br />
QUESTION NO 126<br />
Given:<br />
1. public class OuterClass {<br />
2. private double d1 1.0;<br />
3. //insert code here<br />
4. }<br />
You need to insert an inner class declaration at line2. Which two inner class declarations are valid?<br />
(Choose Two)<br />
A. static class InnerOne {<br />
public double methoda() {return d1;}<br />
}<br />
B. static class InnerOne {<br />
static double methoda() {return d1;}<br />
}<br />
C. private class InnerOne {<br />
public double methoda() {return d1;}<br />
}<br />
D. protected class InnerOne {<br />
static double methoda() {return d1;}<br />
}<br />
E. public abstract class InnerOne {<br />
public abstract double methoda();<br />
}<br />
Answer: C, E<br />
<br />
QUESTION NO 127<br />
Which two declarations prevent the overriding of a method? (Choose Two)<br />
A. Final void methoda() {}<br />
B. Void final methoda() {}<br />
C. Static void methoda() {}<br />
D. Static final void methoda() {}<br />
E. Final abstract void methoda() {}<br />
Answer: A, D<br />
QUESTION NO 128<br />
Given:<br />
1. public class Test {<br />
2. public static void main (String args[]) {<br />
3. class Foo {<br />
4. public int i = 3;<br />
5. }<br />
6. Object o = (Object) new Foo();<br />
7. Foo foo = (Foo)o;<br />
8. System.out.printIn(foo. i);<br />
9. }<br />
10. }<br />
What is the result?<br />
A. Compilation will fail.<br />
B. Compilation will succeed and the program will print “3”<br />
C. Compilation will succeed but the program will throw a ClassCastException at line 6.<br />
D. Compilation will succeed but the program will throw a ClassCastException at line 7.<br />
Answer: B<br />
QUESTION NO 129<br />
Which two create an instance of an array? (Choose Two)<br />
A. int[] ia = new int [15];<br />
B. float fa = new float [20];<br />
C. char[] ca = “Some String”;<br />
D. Object oa = new float[20];<br />
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -