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
ETS User
Post
by ETS User » Fri Mar 11, 2011 6:07 pm
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:
Post
by admin » Sun Mar 13, 2011 6:50 am
The main thread is created by the JVM. The given code does not create any thread.
Guest
Post
by Guest » Thu Mar 01, 2012 9:43 am
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:
Post
by admin » Thu Mar 01, 2012 8:50 pm
The option has now been modified to include the word "exactly" to avoid this confusion.
thank you for your feedback!
Users browsing this forum: No registered users and 9 guests