Welcome Guest | Sign in | Register
Threads - Discussion Page For Q.2948 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Threads > Questions and Answers

Q: 12. public class Starter extends Thread {
private int x = 2;
public static void main(String[] args) throws Exception {
new Starter().makeItSo();
}
public Starter() {
x = 5;
start();
}
public void makeItSo() throws Exception {
join();
x = x - 1;
System.out.println(x);
}
public void run() { x *= 2; }
}

What is the output if the main() method is run?
A. 4 B. 5
C. 8 D. 9
E. Compilation fails.

Answer and Explanation

Answer:9

Explanation:
from main() control will go to Starter() method there x value will become 5. From Starter() it will go to run() here value will become 10. From run() control will go to makeItSo() method here the value of x will be subtracted by 1, so ans is 9. Option D) is correct.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.