Showing posts with label Thread. Show all posts
Showing posts with label Thread. Show all posts

Sunday, 4 March 2012

Sun Certified Java Programmer (SCJP) Questions

Question 1

What will happen if you compile/run this code?

1: public class Q1 extends Thread

2: {

3:    public void run()

4:    {

5:       System.out.println("Before start method");

6:       this.stop();

7:       System.out.println("After stop method");

8:    }

9:

10:   public static void main(String[] args)

11:   {

12:      Q1 a = new Q1();

13:      a.start();

14:   }

15: }

 

A) Compilation error at line 7.

B) Runtime exception at line 7.

C) Prints "Before start method" and "After stop method".

D) Prints "Before start method" only.

Answer : D

Explanation :

Saturday, 21 January 2012

Sun Certified Java Programmer (SCJP) Questions

Which of the following statements is not true about threads ?


Choices:



  • A. If the start() method is invoked twice on the same Thread object, an exception is thrown at runtime.

  • B. The order in which threads were started might differ from the order in which they actually run.

  • C. If the run() method is directly invoked on a Thread object, an