Home Tutorial Java Scjp Part8 SCJP Module-8 Question-4

 
 

Share on Google+Share on Google+
SCJP Module-8 Question-4
Posted on: July 15, 2010 at 12:00 AM
Advertisement
The Sample code given below will check your knowledge of Threads in Java and their different methods in the thread life cycle.

Given a sample code:

public class Test3 {
public static void main(String args[]) {
Test1 pm1 = new Test1("Hi");
pm1.run();
Test1 pm2 = new Test1("Hello");
pm2.run();
}
}

class Test1 extends Thread {
private String sTname = "";

Test1(String s) {
sTname = s;
}

public void run() {
for (int i = 0; i < 2; i++) {
try {
sleep(1000);
} catch (InterruptedException e) {
}
yield();
System.out.println(sTname);
}
}}

Which of the following statement is correct ?

(A) Compilation error
(B) Hi Hi Hello Hello
(C) Hi Hello Hi Hello
(D) Hi Hello

Answer:

(B)

Advertisement

Related Tags for SCJP Module-8 Question-4:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 15, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com