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
Tuesday, February 16, 2010
Pongping Which Statement Is True About The Output Result Of The Following Program?
Subscribe to:
Post Comments (Atom)
2 comments:
Why not learn Java and then answer yourself
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