Showing posts with label run(). Show all posts
Showing posts with label run(). Show all posts

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

Monday, 9 January 2012

Threads in Java - 1

Creating threads


Threads are objects in the Java language. A thread can be defined by extending the java.lang.Thread class or by implementing the java.lang.Runnable interface. The run() method should be overridden and should have the code that will be executed by the new thread. This method must be public with a void return type and should not take any arguments.

Extending thread


If we need to inherit the behavior of the Thread class, we can have a subclass of it. In this case, the disadvantage is that you cannot extend