Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.272 :

Posted: Fri Mar 11, 2011 6:07 pm
by ETS User
The code for the question is -

Code: Select all


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");
		}
	}
}

For the output I chose the answer that "1 new thread is created by the program". Is that not so given that the main() thread is created?

Re: About Question com.enthuware.ets.scjp.v6.2.272 :

Posted: Sun Mar 13, 2011 6:50 am
by admin
The main thread is created by the JVM. The given code does not create any thread.

Re: About Question com.enthuware.ets.scjp.v6.2.272 :

Posted: Thu Mar 01, 2012 9:43 am
by Guest
It will print "Hello World" twice. - It will print "Hello World" thrice.
I thought so, but since it didn't say "exactly twice" it is still true!

Re: About Question com.enthuware.ets.scjp.v6.2.272 :

Posted: Thu Mar 01, 2012 8:50 pm
by admin
The option has now been modified to include the word "exactly" to avoid this confusion.

thank you for your feedback!