JAVA认证真题:SCJP考试题310-025第二套(3)
来源:优易学  2011-11-28 11:02:10   【优易学:中国教育考试门户网】   资料下载   IT书店

 

QUESTION NO: 61
Exhibit
1. public class SyncTest{
2. public static void main(String[] args) {
3. final StringBuffer s1= new StringBuffer();
4. final StringBuffer s2= new StringBuffer();
5. new Thread () {
6. public void run() {
7. synchronized(s1) {
8. s2.append(“A”);
9. synchronized(s2) {
10. s2.append(“B”);
11. System.out.print(s1);
12. System.out.print(s2);
13. }
14. }
15. }
16. }.start();
17. new Thread() {
18. public void run() {
19. synchronized(s2) {
20. s2.append(“C”);
21. synchronized(s1) {
22. s1.append(“D”);
23. System.out.print(s2);
24. System.out.print(s1);
25. }
26. }
27. }
28. }.start();
29. }
30. }
Which two statements are true? (Choose Two)
A. The program prints “ABBCAD”
B. The program prints “CDDACB”
C. The program prints “ADCBADBC”
D. The output is a non-deterministic point because of a possible deadlock condition.
E. The output is dependent on the threading model of the system the program is running on.
Answer: D, B
QUESTION NO: 62
Which method in the Thread class is used to create and launch a new thread of execution?
A. Run();
B. Start();
B. Execute();
C. Run(Runnable r);
D. Start(Runnable r);
E. Execute(Thread t);
Answer: B
-
QUESTION NO: 63
Given:
5. String foo = “base”;
6. foo.substring(0,3);
7. foo.concat(“ket”)
8.
Type the value of foo at line 8.
Answer: BASE
QUESTION NO: 64
Which code determines the int value foo closest to, but not greater than, a double value bar?
A. Int foo = (int) Math.max(bar);
B. Int foo = (int) Math.min(bar);
C. Int foo = (int) Math.abs(bar);
D. Int foo = (int) Math.ceil(bar);
E. Int foo = (int) Math.floor(bar);
F. Int foo = (int) Math.round(bar);
Answer: E
QUESTION NO: 65
Which statement is true?
A. A flow layout can be used to position a component that should resize horizontally when the
container is resized.
B. A grid layout can be used to position a component tat should maintain a constant size even when
the container is resized.
C. A border layout can be used to position component that should maintain a constant size even when
the container is resized.
D. The grid bag layout can be used to give a grid-like layout which differs from the normal grid in
that individual rows and columns can have unique sizes.
E. If two components are placed in the same column of a grid bag layout, and one component resizes
horizontally, then the other component must resize horizontally.
Answer: D
QUESTION NO: 66
Given an ActionEvent, which method allows you to identify the affected Component?
A. Public class getClass()
B. Public Object getSource()
C. Public Component getSource()
D. Public Component getTarget()
E. Public Component getComponent()
F. Public Component getTargetComponent()
Answer: B
QUESTION NO: 67
Exhibit:
1. import java.awt.*;
2.
3. public class Test extends Frame {
4. public Test() {
5. add(new Label(“Hello”) );
6. add(new TextField(“Hello”) );
7. add(new Button(“Hello”) );
8. pack();
9. show();
10. }
11.
12. public static void main(String args[]) {
13. new Test ();
14. }
15. )
What is the result?
A. The code will not compile.
B. A Window will appear containing only a Button.
C. An IllegalArgumentException is thrown at line 6.
D. A Window button will appear but will not contain the Label, TextField, or Button.
E. A Window will appear containing a Label at the top, a TextField below the Label, and a Button
below the TextField.
F. A Window will appear containing a Label on the left, a TextField to the right of the Label, and a
button to the right of the TextField.
Answer: B
QUESTION NO: 68
Exhibit:
1. class A {
2. public int getNumber(int a) {
3. return a + 1;
4. }
5. }
6.
7. class B extends A {
8. public int getNumber (int a) {
9. return a + 2
10. }
11.
12. public static void main (String args[]) {
13. A a = new B();
14. System.out.printIn(a.getNumber(0));
15. }
16. }
What is the result?
A. Compilation succeeds and 1 is printed.
B. Compilation succeeds and 2 is printed.
C. An error at line 8 causes compilation to fail.
D. An error at line 13 causes compilation to fail.
E. An error at line 14 causes compilation to fail.
Answer: B
QUESTION NO: 69
Given:
1. class BaseClass{
2. private float x= 1.0f;
3. protected void setVar (float f) {x = f;}
4. }

5. class SubClass exyends BaseClass {
6. private float x = 2.0f;
7. //insert code here
8. }
Which two are valid examples of method overriding? (Choose Two)
A. Void setVar(float f) {x = f;}
B. Public void setVar(int f) {x = f;}
C. Public void setVar(float f) {x = f;}
D. Public double setVar(float f) {x = f;}
E. Public final void setVar(float f) {x = f;}
F. Protected float setVar() {x=3.0f; return 3.0f; }
Answer: C, E

QUESTION NO: 70
Which statement about static inner classes is true?
A. An anonymous class can be declared as static.
B. A static inner class cannot be a static member of the outer class.
C. A static inner class does not require an instance of the enclosing class.
D. Instance members of a static inner class can be referenced using the class name of the static inner
class.
Answer: C
QUESTION NO: 71
Exhibit:
1. class A {
2. public byte getNumber () {
3. return 1;
4. }
5. }
6.
7. class B extends A {
8. public short getNumber() {
9. return 2;
10. }
11.
12. public static void main (String args[]) {
13. B b = new B ();
14. System.out.printIn(b.getNumber())
15. }
16. }
What is the result?
A. Compilation succeeds and 1 is printed.
B. Compilation succeeds and 2 is printed.
C. An error at line 8 causes compilation to fail.
D. An error at line 14 causes compilation to fail.
E. Compilation succeeds but an exception is thrown at line 14.
Answer: C
QUESTION NO: 72
Given:
AnInterface is an interface.
AnAdapter0 is a non-abstract, non-final class with a zero argument constructor.
AnAdapter1 is a non-abstract, non-final class without a zero argument constructor, but with a constructor that
takes one int argument.
Which two construct an anonymous inner class? (Choose Two)
F. AnAdapter1 aa=new AnAdapter1(){}
G. AnAdapter0 aa=new AnAdapter0(){}
H. AnAdapter0 aa=new AnAdapter0(5){}
I. AnAdapter1 aa=new AnAdapter1(5){}
J. AnInterface a1=new AnInterface(5){}
Answer: B, D
QUESTION NO: 73
Which two statements are true? (Choose Two)
A. An inner class may be declared as static.
B. An anonymous inner class can be declared as public.
C. An anonymous inner class can be declared as private.
D. An anonymous inner class can extend an abstract class.
E. An anonymous inner class can be declared as protected.
Answer: A, D
QUESTION NO: 74
Exhibit:
1. public class Mycircle {
2. public double radius;
3. public double diameter;
4.
5. public void setRadius(double radius)
6. this.radius = radius;
7. this.diameter= radius * 2;
8. }
9.
10. public double getRadius() {
11. return radius;
12. }
13. }
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
Answer: B
QUESTION NO: 75
You want to limit access to a method of a public class to members of the same class. Which access
modifier accomplishes this objective?
A. Public
B. Private
C. Protected
D. Transient
E. No access modifier is required
Answer: B
QUESTION NO: 76
Exhibit:
ClassOne.java
1. package com.abc.pkg1;
2. public class ClassOne {
3. private char var = ‘a';
4. char getVar() {return var;}
5. }
ClassTest.java
1. package com.abc.pkg2;
2. import com.abc.pkg1.ClassOne;
3. public class ClassTest extends ClassOne {
4. public static void main(String[]args) {
5. char a = new ClassOne().getVar();
6. char b = new ClassTest().getVar();
7. }
8. }
What is the result?
A. Compilation will fail.
B. Compilation succeeds and no exceptions are thrown.
C. Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.
D. Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.
Answer: B
QUESTION NO: 77
Given:
1. public class ArrayTest {
2. public static void main (String[]args) {
3. float f1[], f2[];
4. f1 = new float [10];
5. f2 = f1;
6. System.out.printIn (“f2[0]=” + f2[0]);
7. }
8. }
What is the result?
A. It prints f2[0] = 0.0
B. It prints f2[0] = NaN
C. An error at line 5 causes compile to fail.
D. An error at line 6 causes compile to fail.
E. An error at line 6 causes an exception at runtime.
Answer: A

上一页  [1] [2] [3] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训