SCJP考题7

转载 2007年10月13日 15:09:00

685. For an object to be a target for a Thread, that object must be of type:

Fill in the blank.

正确答案: Runnable

 

686. If you supply a target object when you create a new Thread, as in:

Thread t=new Thread(targetObject);

What test of instanceof does targetObject have to pass for this to be legal?

Select the one right answer.

A. targetObject instanceof Thread

B. targetObject instanceof Object

C. targetObject instanceof Applet

D. targetObject instanceof Runnable

E. targetObject instanceof String

正确答案: D

 

687. What appears in the standard output when you run the Dots class?

class Test impltements Runnable{

DotThread t;

public static vokd main(String[]args){

Test d=new Test();

d.t=new DotTgread();

}

public void init(){

t.start();

t=new DashThread().start();

}

}

class DotThread extends Thread{

public void run(){

for(int index=0;index<100;index++)

System.out.print(".");

class DashThread extends Thread{

public void run(){

for(int index=0;index<100;index++)

System.out.print("-");

}

}

Select the one right answer.

A. nothing

B. 100 dots(.)

C. 200 dots(.)

D. 100 dashes(-)

E. 100 dots(.)and 100 dashes(-)

正确答案: A

 

688. If a thread calls the wait() method, which methods can make it continue to run?

A. join()

B. resume()

C. notify()

D. notifyAll()

E. high priority thread is ready

正确答案: C D

 

689. Which method is used to define the execution body of a thread?

A. start()

B. init()

C. run()

D. main()

E. synchronized()

正确答案: C

 

690. Which of the following method can be used to define a new thread class?

A. implemint the Runnable interface

B. add a run() method in the class

C. create an instance of Thread

D. extend the Thread class

正确答案: A D

 

691. Which method you define as the starting point of new thread in a class from which new the thread can be excution?

A. public void start()

B. public void run()

C. public void int()

D. public static void main(String args[])

E. public void runnable()

正确答案: B

 

692. Which modifier should be applied to a method for the lock of object this to be obtained prior to execution any of the method body?

A. synchronized

B. abstract

C. final

D. static

E. public

正确答案: A

 

693. What might cause the current thread to stop executing?

A. An interrupted exception is thrown.

B. The thread execute a sleep() call.

C. The thread constructs a new thread

D. A thread of higher priority becomes ready.

E. The thread executes a read() call on InputStream

正确答案: A B D E

 

694. Which statements are true about threads?

A. A thread can be created only by subclassing java.lang.Thread.

B. Invoking the suspend() method stops a thread so that it cannot be restarted.

C. The java interpreter's natural exit occurs when no non-daemon threads remain alive.

D. Uncoordinated changes to shared data by multiple threads may result in the data being read, or left, in an inconsistemt state.

正确答案: C D

 

695. What statements are true concerning the method notify() that is used in conjunction with wait()?

Select all valid answers.

A. if there is more than one thread waiting on a condition, only the thread that has been waiting the longest is notified

B. if there is more than one thread waiting on a condition, there is no way to predict which thread will be notified

C. notify() is defined in the Thread class

D. it is not strictly necessary to own the lock for the object you invoke notify() for

E. notify() should only be invoked from within a while loop

正确答案: B

 

696. Given the following class:

class Test {

public int startHere=1;

public int endHere=100;

public startic void main(String[] args){

new Test().go();

}

void go(){

//A

Thread 1=new Thread(a);

t.start();

}

}

What block of code can you replace at line A above so that this program will count from startHere to endHere?

Select all valid answers.

A. Runnable a = new Runnable(){

public void run(){

for (int i=starHere;i<=endHere;i++){

System.out.println(i);

}

}

};

B. implements Runnable{/

public void run(){

for(int i=starHere;i<=endHere;i++){

System.out.println(i);

}

}

};

C. Thread a=new Thread(){

public void run(){

for(int i=starHere;i<=endHere;i++)|

System.out.prinln(i);

}

}

};

正确答案: A C

 

697. Which will contain the body of the thread?

A. run()

B. start()

C. stop()

D. main()

E. init()

正确答案: A

 

698. Given the following class:

class Test {

public statie void main(String[]args){

Thread t=new Thread(new CounteBehavior());

t.star();

}

}

Which of the following is a valid definition of CounterBehavior that would make Counter's main() method count from 1 to 100,countingonce per second?

Select the one right answer.

A. //This class is an inner class to Counter;

class CounterBehavior{

for(int i=1;i<=100;i++);

try{

System.out.println(i);

Thread.sleep(1000);

} catch(InterruptedException x){}

}

}

B. //This class is an inner class to Counter;

class CounterBehavior implements Runnable{

public void run(){

for(int i=1; i<=100;i++);

try{

System.out.println(i);

Thread.sleep(1000);

} catch(InterruptedException x){}

}

}

C. //This class is an inner class to Counter;

static class CounterBehavior implements Runnable{

public void run(){

for(int i=1;i<=100;i++){;

try{

System.out.println(i);

Thread.sleep(1000);

}

}catch(InterruptedException x){}

}

}

正确答案: B

 

699. What must be true for the RunHandler class so that instances of RunHandler can be used as written in the code below?

class Test {

public static void main(String[]args){

Thread t=new Thread(new RunHandlr());

t.start();

}

}

Select all valid answers.

A. RunHandler must impement the java.lang.Runnable interface.

B. RunHandler must extend the Thread class.

C. RunHandler must provide a run() method declared as public and returning void.

D. RunHandler must provide an init()method.

正确答案: A C

 

700. What can you write at the comment//A in the code below so that this program writes the word "running" to the standard output?

class Test implements Runnable{

public static void main(String[] args){

Test rt=new Test();

Thread t=new Thread(rt);

//A

}

public void run(){

System.out.println("running");

}

void go(){

start(1);

}

void start(int i){

}

}

Select all volid answers.

A. System.out.println("running");

B. rt.start();

C. rt.go();

D. rt.start(1);

正确答案: A

 

701. What will happen when you attempt to compile and run the following code?

class Test implements Runnable{

int i=0;

publi int run(){

while(true){

i++;

System.out.println("i="+i);

}//End while

return 1;

}

}

Select all valid answers.

A. It will compile and the run method will print out the increasing value of i.

B. It will compile and calling start will print out the increasing value of i.

C. The code will cause an error at compile time.

D. Compilation will cause an error because while cannot take a parameter of true.

正确答案: C

 

702. What will happen when you attempt to compile and run the following cods?

public class Test extends Thread{

public static void main(String argv[]){

Test b=new Test();

b.run();

}

public void start(){

for(int i=0;u<10; i++){

System.out.println("Value of i="+i);

}

}

}

Select the one right answer.

A. A compile time error indicating that no run method is defined for the Thread class.

B. A run time error indicating that no run method is defined for the Thread class.

C. Clean compile and at run time the values 0 To 9 are printed out.

D. Clean compile but no output at runtime.

正确答案: D

 

703. What can cause a thread to stop executing?

A. The program exits via a call to System.exit(0);

B. Amother thread is given a higher priority

C. A call to the thread's stop method.

D. A call to the halt method of the Thread class

正确答案: A B C

 

704. Under what circumstances might you use the yield method of the Thread class?

A. To call from the currently running thread to allow another thread of the same or higher priority to run.

B. To call on a waiting thread to allow it to run

C. To allow a thread of higher priority to run

D. To call from the currently running thread with a parameter designating which thread should be allowed to run

正确答案: A

 

705. Which of the following statements about threading are true?

A. You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements Runnable.

B. You can obtain a mutually exclusive lock on any object.

C. A thread can obtain a mutually exclusive lock on a synchronized method of an object.

D. Thread scheduling algorithms are platform dependent.

正确答案: B C D

 

706. Which of the following are methods of the Thread class?

A. yield()

B. sleep(long msec)

C. go()

D. stop()

正确答案: A B D

 

707. Which of the following best describes the use of the synchronized keyword?

A. Allows two process to run in parallel but to communicate with each other

B. Ensures only one thread at a time may access a method or object

C. Ensures that two or more processes will start and end at the same time

D. Ensures that two or more Threads will start and end at the same time

正确答案: B

 

708. Which of the following are methods of the Runnable interface?

A. run

B. start

C. yield

D. stop

正确答案: A

 

709. What will happen when you attempt to compile and run the following code?

public calss Test extends Thread{

public static void main(String argv[]){

Test b=new Test();

b.start();

}

public void run(){

System.out.println("Running");

}

}

Select the one right answer.

A. Compilation and run but no output

B. Compilation and run with the output "Running"

C. Compile time error with complaint of no Thread targer

D. Compile time error with complaint of no access to Thread package

正确答案: B

 

710. Given a reference called t to a class which extends Thread. which of the following will cause it to give up cycles to allow another thread to execute

A. t.yield();

B. yield();

C. yield(100);//Or sone other suitable amount in milliseconds

D. yield(t);

正确答案: A B

 

711. Select all the exceptions thrown by wait() method of an Object class, which you can replace in the place of xxx legally?

class Test implements Runnable{

public void run(){

System.out.println("Execrting run() method");

myTest();

}

public synchronized void myTest(){

  try{

wait(-1000);

System.out.println("Execrting the myTest() method");

}XXX

}

}

public class MyTest{

public static void main(String args[]){

Test t=new Test();

Thread th=new Thread(t);

th.start();

}

}

Select the one right answer.

A. catch (InterruptedException ie){}

B. catch (IllegalArgumentException i1){}

C. catch (IllegalMonitorStateException i1){}

D. Only catch (InterruotedException e){} exception

正确答案: A B C

 

712. There are 20 threads are waiting in the waiting pool with same priority. how can you invokes 15th thread from the wailing pool?

A. By calling resume() method

B. By calling interrupt() method

C. Calling call() method

D. By calling notify(15)method on the thread instance

E. None of the above

正确答案: E

 

713. Please select all correct statements from the following.

A. toString() method is defined in Object class.

B. toString() method is defined in Class class.

C. wait(), notify(), notifyAll() methods are defined in Object class and used for Thread communication.

D. toString() method provides string representation of an Object state.

正确答案: A C D

 

714. What does the following code do?

public class Test implements Runnable{

public void run (String s){

System.out.println("Executing Runnable Interface Thread");

}

public static void main(String args[]){

Test rt=new Test();

Thread t=new Thread(rt);

t.start();

}

}

Select the one right answer.

A. The compiler error

B. The runtime error

C. Comliles and prints "Execrting Runnable Interface Thread" on the screen

D. Comliles and does not print any thing on the screen

正确答案: A

 

715. Which statements are true?

A. Threads start() method makes it eligible to run

B. Thread dies after the run() returns

C. A dead Thread can be started again.

D. A stop() method kills the currently running Thread

正确答案: A B D

 

716. Which keyword should be used to enable interaction with the lock of an object?

The flag allows exclusive access to that object.

A. transient

B. synchronized

C. serialize

D. static

正确答案: B

 

717. Which statements about thread are true?

A. Once a thread is created, it can start running immediately.

B. To use the start() method makes a thread runnable, but it does not necessarily start immediately.

C. When a thread stops running because of pre-emptive, it is placed at the front end of the runnable queue.

D. A thread may cease tp be ready for a variety of reasons.

正确答案: B D

 

718. The method resrme() is responsible for resuming which thread's execution?

A. The thread which is stopped by calling method stop()

B. The thread which is stopped by calling method steep()

C. The thread which is stopped by calling method wait()

D. The thread which is stopped by calling method suspend()

正确答案: D

 

719. What will happen if you compile/run this code?

1: public class Test extends Thread

2: {

3: public void run()

4: {

5: System.out.println("Before start method");

6: this.stop();

7: System.out.println("After stop method");

8: }

9:

10: public static void main(String[] args)

11: {

12: Test a=new Test();

13: a.start();

14:}

15:}

Select the one right answer.

A. Compilation error at line 7.

B. Runtime exception at line 7.

C. Prints"Before start method" and "After stop method".

D. Prints"Before start method" only.

正确答案: D

 

720. Under which conditions will a currently executing thread stop?

A. When an interrupted exception occurs

B. When a thread of higher priority is ready(becones runnable)

C. When the thread creates a new thread

D. When the stop() method is called.

正确答案: A B D

 

721. What happens when you try to compile and run the following application?

public class Test{

public static void main(String[] args){

new Test();

}

Test(){

Test alias1=this;

Test alias2=this;

synchronized(alias1){

try{

slias2.wait();

System.out.println("DONE WAITING");

}

Catch(InterruptedException e){

System.out.println("INTERR UPTED");

}

catch(Exception e){

System.out.println("OTHER EXCEPTION");

}

finally{

System.out.println("FINALLY");

}

}

System.out.println("ALL DONE");

}

}

Choose all correct options.

A. The application compiles but doesn't print anything.

B. The application compiles and print"DONE WAITING"

C. The application compiles and print "FINALLY"

D. The application compiles and print "ALL DONE"

E. The application compiles and print "INTERRUPTED"

正确答案: A

 

722. What is the name of the interface that can be used to define a class that can execute within its own thread?

Selecs the most appropriate answer.

A. Runnable

B. Run

C. Threadable

D. Thread

E. Executable

正确答案: A

 

723. Which is the name of the method used to schedule a thread for execution?

Select the most appropriate answer.

A. inpt();

B. start();

C. run();

D. resume();

E. sleep();

正确答案: B

 

724. Which method may cause a thread to stop executing?

Select all correct answers.

A. sleep();

B. stop();

C. yield();

D. wait();

E. notify();

F. notifyAll();

G. synchronized()

正确答案: A B C D

 

725. What is the effect of issuing a wait() method on an object?

Select the most appropriate answer

A. If a notify() method has already been sent to that object then it has no effect.

B. The object issuing the call to wait() will halt until another object sends a notify() or nutifyAll() method.

C. An exception will be raised.

D. The object issuing the call to wait() will be automatically synchronized with any other objects using the receiving object.

正确答案: B

 

726. What is the result of compiling and executing the following Java class:

public class Test extends Thread{

public void run(){

System.out.println("In run");

suspend();

resume();

System.out.println("Leaving run");

}

public static void main(Syring args[]){

(new Test()).start();

}

}

Select the most appropriate answer.

A. Compilation will fail in the method main.

B. Compilation will fail in the method run.

C. A warning will be generated for method run.

D. The string" In run" will be printed to standard out.

E. Both strings will be printed tp standard out.

F. Nothing will happen.

正确答案: D

 

727. What will happen if you compile/run this code?

1: public class Test implements Runnable

2: {

3: public void run(String s)

4: {

5: System.out.println("Before start Thread:"+s);

6:

7: System.out.println("After stop of Thread:"+a);

8: }

9:

10:public static void main(String[] args)

11:{

12:Test a=new Test();

13:Thread t=new Thread(a);

14:t.start();}

15:}

Select the one right answer.

A. Compilation error

B. Runtime exception

C. Compilation error at line 14

D. Prints "Before start of Thread" After Start of Thread

正确答案: A

 

728. What is the name of the method used to start a thread execution?

A. init();

B. start();

C. run();

D. resume();

正确答案: B

 

729. Which will contain the body of the thread?

A. run()

B. start()

C. stop()

D. main()

E. init()

正确答案: A

 

730. Which method is used to construct and execute the thread?

A. execte()

B. run()

C. build()

D. start()

正确答案: D

 

731. Which of the following will not directly cause a thread to stop?

A. notify()

B. wait()

C. notifyAll()

D. sleep()

正确答案: A C

 

732. Which of the following statements are true?

A. all the threads created in a class will come to an end at the same tine.

B. you can stop a thread indefinitely if you wish to.

C. you can start a thread only by extending the Thread class.

D. multiple threads accessing same variable will lead to producing junk(not the exact word )data.

E. JVM exits after the main() thread is exited even if there might be some threads running.

正确答案: B D

 

 

SCJP试题七

685. For an object to be a target for a Thread, that object must be of type:Fill in the blank.正确答案: ...
  • lili6755
  • lili6755
  • 2009年12月23日 23:48
  • 684

Objective-C 警告相关说明

原文地址:http://nshipster.com/clang-diagnostics/
  • icmmed
  • icmmed
  • 2014年09月03日 16:36
  • 9893

FindBugs Report安全代码检查工具问题解析

1、LI_LAZY_INIT_UPDATE_STATIC:Incorrect lazy initialization and update of static field Thismethod con...
  • wwbmyos
  • wwbmyos
  • 2016年01月20日 20:14
  • 5811

JAVA 静态代码分析--规范检查-checkstyle

JAVA 代码分析 http://www.oschina.net/question/129540_23043
  • magic_wz
  • magic_wz
  • 2013年11月19日 11:36
  • 10655

SCJP模拟考题140题(310-025)

  • 2011年03月05日 09:13
  • 109KB
  • 下载

SCJP考题解析(简体)---免费

  • 2009年04月13日 23:54
  • 1.38MB
  • 下载

SCJP_6.0认证教战手册考题1-244.pdf

  • 2012年09月09日 20:42
  • 623KB
  • 下载

SCJP考题中的陷阱

  • 2007年05月18日 13:22
  • 45KB
  • 下载

SCJP考题中的陷阱

  • 2008年05月29日 23:16
  • 30KB
  • 下载

最新SCJP考题资料

  • 2009年03月16日 11:01
  • 3.08MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:SCJP考题7
举报原因:
原因补充:

(最多只允许输入30个字)