Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'Thread class' - 4 question(s) found - Order By Newest | ||||
| ||||
Ans. Thread class holds the definition of start method ( This is the method that starts execution of new thread and then calls run method within the scope of new thread ). Interfaces don't hold any definition and so does runnable. So it makes it necessary the usage of Thread class , whatever implementation you choose. When your class extends the thread class, it carries the definition of start method from parent Thread class onto itself and hence new yourClass.start() helps starting a new thread and then executing run method in that new thread scope. When you implement runnable interface , you are just making it sure to the JVM that you have implemented the required method ( run() ) which the Thread start method will look for upon executing start method. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. http://www.buggybread.com/2015/02/java-threads-classes-that-inherit.html | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public class MyClass { static class MyThreadClass extends Thread{ @Override public void run() { System.out.println("Hello"); try { Thread.sleep(1000); System.out.println("Hello Again"); } catch (InterruptedException e) { e.printStackTrace(); } } } public static void main(String[] args){ MyThreadClass myThreadClass = new MyThreadClass(); myThreadClass.start(); MyThreadClass myThreadClass2 = new MyThreadClass(); myThreadClass2.start(); } } | ||||
![]() | ||||
![]() ![]() ![]() | ||||