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

📄 中文java技术网scjp考试题310-025(第二套3)51-91-147.htm

📁 这是多次JAVA考试试题或模拟试题集锦
💻 HTM
📖 第 1 页 / 共 3 页
字号:
20. ) catch (Exception e) {}<br />
21. )<br />
22. )<br />
Which statement al line 17 will ensure that j=10 at line 19?<br />
A. a.wait();<br />
B. t.wait();<br />
C. t.join();<br />
D. t.yield();<br />
E. t.notify();<br />
F. a.notify();<br />
G. t.interrupt();<br />
Answer: C<br />
Question No 59<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 synchronized 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. An error at line 11 causes compilation to fail.<br />
B. Errors at lines 7 and 8 cause compilation to fail.<br />
C. 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 />
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 twice (for example, “x=1, y=1” followed by<br />
“x=1, y=1”)<br />
E. 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=2s, y=2”)<br />
Answer: E<br />
QUESTION NO: 60<br />
Which two CANNOT directly cause a thread to stop executing? (Choose Two)<br />
A. Existing from a synchronized block.<br />
B. Calling the wait method on an object.<br />
C. Calling notify method on an object.<br />
D. Calling read method on an InputStream object.<br />
E. Calling the SetPriority method on a Thread object.<br />
Answer: A, C<br />
QUESTION NO: 61<br />
Exhibit<br />
1. public class SyncTest{<br />
2. public static void main(String[] args) {<br />
3. final StringBuffer s1= new StringBuffer();<br />
4. final StringBuffer s2= new StringBuffer();<br />
5. new Thread () {<br />
6. public void run() {<br />
7. synchronized(s1) {<br />
8. s2.append(“A”);<br />
9. synchronized(s2) {<br />
10. s2.append(“B”);<br />
11. System.out.print(s1);<br />
12. System.out.print(s2);<br />
13. }<br />
14. }<br />
15. }<br />
16. }.start();<br />
17. new Thread() {<br />
18. public void run() {<br />
19. synchronized(s2) {<br />
20. s2.append(“C”);<br />
21. synchronized(s1) {<br />
22. s1.append(“D”);<br />
23. System.out.print(s2);<br />
24. System.out.print(s1);<br />
25. }<br />
26. }<br />
27. }<br />
28. }.start();<br />
29. }<br />
30. }<br />
Which two statements are true? (Choose Two)<br />
A. The program prints “ABBCAD”<br />
B. The program prints “CDDACB”<br />
C. The program prints “ADCBADBC”<br />
D. The output is a non-deterministic point because of a possible deadlock condition.<br />
E. The output is dependent on the threading model of the system the program is running on.<br />
Answer: D, B<br />
QUESTION NO: 62<br />
Which method in the Thread class is used to create and launch a new thread of execution?<br />
A. Run();<br />
B. Start();<br />
B. Execute();<br />
C. Run(Runnable r);<br />
D. Start(Runnable r);<br />
E. Execute(Thread t);<br />
Answer: B<br />
-<br />
QUESTION NO: 63<br />
Given:<br />
5. String foo = “base”;<br />
6. foo.substring(0,3);<br />
7. foo.concat(“ket”)<br />
8.<br />
Type the value of foo at line 8.<br />
Answer: BASE<br />
QUESTION NO: 64<br />
Which code determines the int value foo closest to, but not greater than, a double value bar?<br />
A. Int foo = (int) Math.max(bar);<br />
B. Int foo = (int) Math.min(bar);<br />
C. Int foo = (int) Math.abs(bar);<br />
D. Int foo = (int) Math.ceil(bar);<br />
E. Int foo = (int) Math.floor(bar);<br />
F. Int foo = (int) Math.round(bar);<br />
Answer: E<br />
QUESTION NO: 65<br />
Which statement is true?<br />
A. A flow layout can be used to position a component that should resize horizontally when the<br />
container is resized.<br />
B. A grid layout can be used to position a component tat should maintain a constant size even when<br />
the container is resized.<br />
C. A border layout can be used to position component that should maintain a constant size even when<br />
the container is resized.<br />
D. The grid bag layout can be used to give a grid-like layout which differs from the normal grid in<br />
that individual rows and columns can have unique sizes.<br />
E. If two components are placed in the same column of a grid bag layout, and one component resizes<br />
horizontally, then the other component must resize horizontally.<br />
Answer: D<br />
QUESTION NO: 66<br />
Given an ActionEvent, which method allows you to identify the affected Component?<br />
A. Public class getClass()<br />
B. Public Object getSource()<br />
C. Public Component getSource()<br />
D. Public Component getTarget()<br />
E. Public Component getComponent()<br />
F. Public Component getTargetComponent()<br />
Answer: B<br />
QUESTION NO: 67<br />
Exhibit:<br />
1. import java.awt.*;<br />
2.<br />
3. public class Test extends Frame {<br />
4. public Test() {<br />
5. add(new Label(“Hello”) );<br />
6. add(new TextField(“Hello”) );<br />
7. add(new Button(“Hello”) );<br />
8. pack();<br />
9. show();<br />
10. }<br />
11.<br />
12. public static void main(String args[]) {<br />
13. new Test ();<br />
14. }<br />
15. )<br />
What is the result?<br />
A. The code will not compile.<br />
B. A Window will appear containing only a Button.<br />
C. An IllegalArgumentException is thrown at line 6.<br />
D. A Window button will appear but will not contain the Label, TextField, or Button.<br />
E. A Window will appear containing a Label at the top, a TextField below the Label, and a Button<br />
below the TextField.<br />
F. A Window will appear containing a Label on the left, a TextField to the right of the Label, and a<br />
button to the right of the TextField.<br />
Answer: B<br />
QUESTION NO: 68<br />
Exhibit:<br />
1. class A {<br />
2. public int getNumber(int a) {<br />
3. return a + 1;<br />
4. }<br />
5. }<br />
6.<br />
7. class B extends A {<br />
8. public int getNumber (int a) {<br />
9. return a + 2<br />
10. }<br />
11.<br />
12. public static void main (String args[]) {<br />
13. A a = new B();<br />
14. System.out.printIn(a.getNumber(0));<br />
15. }<br />
16. }<br />
What is the result?<br />
A. Compilation succeeds and 1 is printed.<br />
B. Compilation succeeds and 2 is printed.<br />
C. An error at line 8 causes compilation to fail.<br />
D. An error at line 13 causes compilation to fail.<br />
E. An error at line 14 causes compilation to fail.<br />
Answer: B<br />
QUESTION NO: 69<br />
Given:<br />
1. class BaseClass{<br />
2. private float x= 1.0f;<br />
3. protected void setVar (float f) {x = f;}<br />
4. }<br />
<br />
5. class SubClass exyends BaseClass {<br />
6. private float x = 2.0f;<br />
7. //insert code here<br />
8. }<br />
Which two are valid examples of method overriding? (Choose Two)<br />
A. Void setVar(float f) {x = f;}<br />
B. Public void setVar(int f) {x = f;}<br />
C. Public void setVar(float f) {x = f;}<br />
D. Public double setVar(float f) {x = f;}<br />
E. Public final void setVar(float f) {x = f;}<br />
F. Protected float setVar() {x=3.0f; return 3.0f; }<br />
Answer: C, E<br />
QUESTION NO: 70<br />
Which statement about static inner classes is true?<br />
A. An anonymous class can be declared as static.<br />
B. A static inner class cannot be a static member of the outer class.<br />
C. A static inner class does not require an instance of the enclosing class.<br />
D. Instance members of a static inner class can be referenced using the class name of the static inner<br />
class.<br />
Answer: C<br />
QUESTION NO: 71<br />
Exhibit:<br />
1. class A {<br />
2. public byte getNumber () {<br />
3. return 1;<br />
4. }<br />
5. }<br />
6.<br />
7. class B extends A {<br />
8. public short getNumber() {<br />
9. return 2;<br />
10. }<br />
11.<br />
12. public static void main (String args[]) {<br />
13. B b = new B ();<br />
14. System.out.printIn(b.getNumber())<br />
15. }<br />
16. }<br />
What is the result?<br />
A. Compilation succeeds and 1 is printed.<br />
B. Compilation succeeds and 2 is printed.<br />
C. An error at line 8 causes compilation to fail.<br />
D. An error at line 14 causes compilation to fail.<br />
E. Compilation succeeds but an exception is thrown at line 14.<br />
Answer: C<br />
QUESTION NO: 72<br />
Given:<br />
AnInterface is an interface.<br />
AnAdapter0 is a non-abstract, non-final class with a zero argument constructor.<br />
AnAdapter1 is a non-abstract, non-final class without a zero argument constructor, but with a constructor that<br />
takes one int argument.<br />
Which two construct an anonymous inner class? (Choose Two)<br />
F. AnAdapter1 aa=new AnAdapter1(){}<br />
G. AnAdapter0 aa=new AnAdapter0(){}<br />
H. AnAdapter0 aa=new AnAdapter0(5){}<br />
I. AnAdapter1 aa=new AnAdapter1(5){}<br />
J. AnInterface a1=new AnInterface(5){}<br />
Answer: B, D<br />
QUESTION NO: 73<br />
Which two statements are true? (Choose Two)<br />
A. An inner class may be declared as static.<br />
B. An anonymous inner class can be declared as public.<br />
C. An anonymous inner class can be declared as private.<br />
D. An anonymous inner class can extend an abstract class.<br />
E. An anonymous inner class can be declared as protected.<br />
Answer: A, D<br />
QUESTION NO: 74<br />
Exhibit:<br />
1. public class Mycircle {<br />
2. public double radius;<br />
3. public double diameter;<br />
4.<br />
5. public void setRadius(double radius)<br />
6. this.radius = radius;<br />
7. this.diameter= radius * 2;<br />
8. }<br />
9.<br />
10. public double getRadius() {<br />
11. return radius;<br />
12. }<br />
13. }<br />
Which statement is true?<br />
A. The Mycircle class is fully encapsulated.<br />
B. The diameter of a given MyCircle is guaranteed to be twice its radius.<br />
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.<br />
D. The radius of a MyCircle object can be set without affecting its diameter.<br />
Answer: B<br />
QUESTION NO: 75<br />
You want to limit access to a method of a public class to members of the same class. Which access<br />
modifier accomplishes this objective?<br />
A. Public<br />
B. Private<br />
C. Protected<br />
D. Transient<br />
E. No access modifier is required<br />
Answer: B<br />
QUESTION NO: 76<br />
Exhibit:<br />
ClassOne.java<br />
1. package com.abc.pkg1;<br />
2. public class ClassOne {<br />
3. private char var = ‘a’;<br />
4. char getVar() {return var;}<br />
5. }<br />
ClassTest.java<br />
1. package com.abc.pkg2;<br />
2. import com.abc.pkg1.ClassOne;<br />
3. public class ClassTest extends ClassOne {<br />
4. public static void main(String[]args) {<br />
5. char a = new ClassOne().getVar();<br />
6. char b = new ClassTest().getVar();<br />
7. }<br />
8. }<br />
What is the result?<br />

⌨️ 快捷键说明

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