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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ETS User

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

Post 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?

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

The main thread is created by the JVM. The given code does not create any thread.

Guest

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

Post 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!

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

The option has now been modified to include the word "exactly" to avoid this confusion.

thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests