Concurrency topic wise question 8

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
vijaykohli

Concurrency topic wise question 8

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

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

Re: Concurrency topic wise question 8

Post by admin »

Hello,
The main thread is created by JVM and not by the program code.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 44 guests