Page 1 of 1

Concurrency topic wise question 8

Posted: Sun Mar 20, 2011 5:10 pm
by vijaykohli
class MyClass implements Runnable
{
int n = 0;
public MyClass(int n){ this.n = n; }
public static void main(String[] args)
{
new MyClass(2).run();
new MyClass(1).run();
}
public void run()
{
for(int i=0; i<n; i++)
{
System.out.println("Hello World");
}
}
}

What will be the output when this program is compiled and run from the command line?

Should'nt the answer be
1 new thread is created by the program.
as the main method itself is a thread?

Re: Concurrency topic wise question 8

Posted: Sun Mar 20, 2011 6:30 pm
by admin
Hello,
The main thread is created by JVM and not by the program code.

HTH,
Paul.