Concurrency topic wise question 8
Posted: Sun Mar 20, 2011 5:10 pm
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?
{
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?