SCJP模拟题 AND Answer[2]

2019-08-30 12:58

Q1

Here is part of the code for a class which implements the Runnable interface. 1. public class Whiffler extends Object implements Runnable { 2. Thread myT ;

3. public void start(){ 4. myT = new Thread( this ); 5. }

6. public void run(){ 7. while( true ){ 8. doStuff(); 9. }

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

12. // more class code

Assume that the rest of the class defines doStuff, etc and that the class compiles without error. Also assume that a Java application creates a Whiffler object and calls the Whiffler start method, that no other direct calls to Whiffler methods are made an that the Thread in this object is the only one the application creates. Which of the following are correct statements ?

a. The doStuff method will be called repeatedly. b. The doStuff method will never be executed. c. The doStuff method will execute at least one time. d. The statement in line 10 will never be reached.

Q2

Here is a method which creates a number of String objects in the course of printing a count down sequence.

1. public void countDown() {

2. for( int i = 10 ; i >= 0 ; i-- ){ 3. String tmp = Integer.toString( i ); 4. System.out.println( tmp ); 5. }

6. System.out.println(\7. }

When the program reaches line 6, how many of the String objects created in line 3 are eligible for garbage collection? Assume that the System.out object is not keeping a reference. a. none b. 1 c. 10 d. 11

Q3

Select all of the following methods that are instance methods of the Thread class, excluding any methods deprecated in Java 1.2.

a. start() b. stop() c. run() d. suspend()

e. sleep( long msec ) f. toString()

Q4

You are writing a set of classes related to cooking and have created your own exception hierarchy derived from java.lang.Exception as follows Exception

+-- BadTasteException +-- BitterException +-- SourException

Your base class, \int rateFlavor(Ingredient[] list) throws BadTasteException

A class, \

BaseCook.rateFlavor(). Which of the following are legal declarations of the overriding method?

a. int rateFlavor(Ingredient[] list) throws BadTasteException b. int rateFlavor(Ingredient[] list) throws Exception c. int rateFlavor(Ingredient[] list) throws BitterException d. int rateFlavor(Ingredient[] list)

Q5

You are working on an aquarium simulation class named Aquarius. You already have a method which adds a Fish object to the aquarium and returns the remaining fish capacity. This method has the following declaration. public int addFish( Fish f )

Now you want to provide for adding a whole shoal of fish at once. The proposed method declaration is

protected boolean addFish( Fish[] f )

The idea being that it will return true if there is more room in the tank or false if the tank now too full. Which of the following statements about this proposal are true? a. This technique is called overloading. b. This technique is called overriding.

c. The compiler will reject the new method because the return type is different. d. The compiler will reject the new method because the access modifier is different.

Q6

You have created a TimeOut class as an extension of Thread, the purpose being to print a \

Here is the run method which you have coded. 1. public void run(){

2. System.out.println(\3. try {

4. Thread.sleep(10000 );

5. System.out.println(\6. } catch(InterruptedException e) { 7. System.out.println(\8. } 9. }

Given that a program creates and starts a TimeOut object, which of the following statements is true?

a. Exactly 10 seconds after the start method is called, \b. Exactly 10 seconds after \c. The delay between \

minus one tick of the system clock.

d. If \\Q7

What is the output of the following program?

1. class Base { 2. int x=3;

3. public Base() {}

4. public void show() {

5. System.out.print(\6. } 7. }

8. class Derived extends Base { 9. int x=2;

10. public Derived() {}

11. public void show() {

12. System.out.print(\13. } 14. }

15. public class Test {

16. public static void main(String args[]) { 17. Base b = new Derived(); 18. b.show();

19. System.out.println(\20. }

21. } // end of class Test

a. The value is 3 The value is 2 b. The value is 2 The value is 3

c. The value is 3 The value is 3 d.The value is 2 The value is 2 Q8

What is the output of the following code?

1. public class Note {

2. public static void main(String args[]) { 3. String name[] = {\4. String name0 = \5. String name1 = \6. swap(name0,name1);

7. System.out.println(name0 + \8. swap(name);

9. System.out.println(name[0] + \10. }

11. public static void swap(String name[]) { 12. String temp; 13. temp=name[0]; 14. name[0]=name[1]; 15. name[1]=temp; 16. }

17. public static void swap(String name0,String name1) { 18. String temp; 19. temp=name0; 20. name0=name1; 21. name1=temp; 22. }

23. } // end of Class Note

a. Killer,Miller followed by Killer,Miller b. Miller,Killer followed by Killer,Miller c. Killer,Miller followed by Miller,Killer d. Miller,Killer followed by Miller,Killer

Q9

What is the output of the following program?


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

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

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

马上注册会员

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