Wednesday, 1 November 2017

#10. SCJP/OCJP Exams Questions & Answers-


10. Given:
 public class Threads4 {
 public static void main (String[] args) {
 new Threads4().go();
 }
public void go() {
 Runnable r = new Runnable() {
 public void run() {
 System.out.print("foo");
 }
 };
 Thread t = new Thread(r);
 t.start();
 t.start();
 }
 }
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes normally and prints "foo".
D. The code executes normally, but nothing is printed.

Correct Answer:  B

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. ...