Tuesday, February 16, 2010

Pongping Which Statement Is True About The Output Result Of The Following Program?

Which statement is true about the output result of the following program? - pongping

public class PingPong (

synchronized public static void main (String [] a) (
Thread t = new Thread () (

@ Override
public void run () (
pong ();
)
);

t.run ();
System.out.println ( "Ping");
)

static void pong () (
System.out.println ( "Pong");
)
)

a. always PingPong
b. PingPong sometimes and sometimes PongPing
c. PongPing always, it is not multi-threaded
d. There is an exception

2 comments:

dt192 said...

Why not learn Java and then answer yourself

Ravi Chandra said...

The answer is (b).

If you t.run () call, start a new thread of execution, therefore, has two son in each (of the new and the main thread). The behavior of a wire in most cases can not be predicted, would be than here. If tennis () is called first, Pong is first printed, otherwise it would be printed Ping. Here, too, anything can happen in the execution!

Post a Comment