Tuesday, 31 October 2017

#8. SCJP/OCJP Exams Questions & Answers-


8. What is the output if the main() method is run?
public class Starter extends Thread{
private int k=2
public Static void main(String[] args) throws Exception{
new starter().makeItDo();
}
public Starter(){
k=5;
start();
}
public void makeItDo() throws Exception{
join();
k=k-1;
System.out.println(k);
}
public void run(){
k*=2
}
}
A. 4
B. 5
C. 8
D. 9
E. Compilation fails.
F. An exception is thrown at runtime.
G. It is impossible to determine for certain.

Answer: D

No comments:

Post a Comment

#45 to #51 SCJP/OCJP Exams Questions & Answers-

45. Given: 1. public class A { 2. public void doit() { 3. } 4. public String doit() { 5. return "a"; 6. } 7. ...