SCJP模拟题 AND Answer[2](7)

2019-08-30 12:58

c. java.io.FileWriter

d. java.io.OutputStreamWriter Q71

Which of the following events has a matching adapter class that implements the appropriate listener interface?

Select all correct answers. a. java.awt.event.MouseEvent b. java.awt.event.ActionEvent c. java.awt.event.FocusEvent d. java.awt.event.ItemEvent

Q72

Here is a partial listing of a class to represent a game board in a networked game. It is desired to prevent collisions due to more than one Thread using the addPic method to modify the array of Image references. 1. class Board extends Object { 2. Image[] pics = new Image[64]; 3. int active = 0;

4. public boolean addPic( Image mg, int pos) { 5. synchronized (this) { 6. if (pics[pos] == null)

7. { active++ ; pics[pos] = mg; return true; } 8. else

9. return false; 10. } 11. }

12. // remainder of class

Select all the alternatives for line 5 that would accomplish this. a. synchronized (this) b. synchronized (pics) c. synchronized (mg) d. synchronized (active)

Q73

Given an object created by the following class

1. class Example extends Object { 2. public void Increment (Integer N) { 3. N = new Integer( N.intValue() + 1); 4. }

6. public void Result(int x) { 7. Integer X = new Integer(x); 8. Increment(X);

9. System.out.println(\10. } 11. }

What happens when a program calls the Result method with a value of 30? a. The message \b. The message \c. The message \d. The program fails to compile. Q74

What is the output of the following program

1. public class Test { 2. private int i = giveMeJ(); 3. private int j = 10; 4.

5. private int giveMeJ() { 6. return j; 7. } 8.

9. public static void main(String args[]) { 10. System.out.println((new AQuestion()).i); 11. } 12. }

Select one correct answer

a. Compiler error complaining about access restriction of private variables of AQuestion. b. Compiler error complaining about forward referencing. c. No Compilation error - The output is 0; d. No Compilation error - The output is 10;

Q75

What is the result of compiling the following program 1. public class Test {

2. public static void main(String args[]) { 3. System.out.println(\4. try {

5. } catch(java.io.IOException t) { 6. System.out.println(\7. }

8. System.out.println(\9. } 10. }

Select one correct answer a. No Compilation Error.

b. Compiler error complaining about the catch block where no IOException object can ever be thrown.

c. Compiler error - IOException not found. It must be imported in the first line of the code. d. No compiler error. The lines \Q76

Read the following snippet carefully

1. public synchronized void someMethod() { 2. //lots of code 3. try {

4. Thread.sleep(500);

5. } catch(InterruptedException e) { 6. //do some things here. 7. }

8. //more and more code here 9. }

Select all correct answers

a. The code causes compilation error - sleep cannot be called inside synchronized methods. b. The Thread sleeps for at least 500 milliseconds in this method if not interrupted. c. When the thread \d. The \

Q77

What will be the result of attempt to compile and the run the following code 1. public class ADirtyOne {

2. public static void main(String args[]) { 3. System.out.println(Math.abs(Integer.MIN_VALUE)); 4. } 5. }

Select one correct answer a. Causes a compilation error.

b. Causes no error and the value printed on the screen is less than zero.

c. Causes no error and the value printed on the screen is one more than Integer.MAX_VALUE d. Will throw a runtime exception due to overflow - Integer.MAX_VALUE is less in magnitue than Integer.MIN_VALUE.

Q78

What is the result of attempting to compile and run the following program

1. public class Test {

2. public void method(Object o) { 3. System.out.println(\4. }

5. public void method(String s) { 6. System.out.println(\7. }

8. public static void main(String args[]) { 9. Test test = new Test(); 10. test.method(null); 11. } 12. }

Select one correct answer a. The code does not compile.

b. The code compiles cleanly and shows \c. The code compiles cleanly and shows \d. The code throws an Exception at Runtime.

Q79

What is the result of attempting to compile the following program 1. public class Test {

2. public void method(StringBuffer sb) { 3. System.out.println(\4. }

5. public void method(String s) { 6. System.out.println(\7. }

8. public static void main(String args[]) { 9. Test test = new Test(); 10. test.method(null); 11. } 12. }

Select one correct answer a. The code does not compile.

b. The code compiles correctly and shows \c. The code compiles correctly and shows \d. The code throws an Exception at Runtime. Q80

What is the requirement of the class which implements the following Interface

1. public interface Test { 2. void someMethod(); 3. }

Select all correct answers

a. Should have someMethod which must be necessarily declared as public. b. Should have someMethod which could be \

c. Should have someMethod which should not throw any checked exceptions.

d. Should have someMethod which cannot be sychronized as sychronized is not in the signature of the interface definition.

Q81

What is the result of attempting to compile and run the following program?


SCJP模拟题 AND Answer[2](7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:自考混凝土及砌体结构模拟试题A卷(附答案)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: