VOOZH about

URL: https://www.geeksforgeeks.org/java/output-of-java-programs-set-46-multi-threading/

⇱ Output of Java Programs | Set 46 (Multi-Threading) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Output of Java Programs | Set 46 (Multi-Threading)

Last Updated : 4 Oct, 2017
Prerequisite : Multi-threading in Java 1. What will be the output of the program? Options: 1. One thread created 2. Two thread created 3. Depend upon system 4. No thread created Output:
 The answer is option (2)
Explanation : In the above program, one thread will be created i.e. the main thread which is responsible to execute the main() method and the child thread will be created after the execution of t.start() which is responsible to execute run() method. 2. What will be the output of the program? Options: 1. One thread created 2. Two thread created 3. Depend upon system 4. No thread created Output:
 The answer is option (1)
Explanation : In the above program only one thread will be created i.e. the main thread which is responsible to execute the main() method only. The run() method is called by the object t like a normal method. 3. What will be the order of output of the program? Options: 1. Main Run 2. Run Main 3. Depend upon Program 4. Depend upon JVM Output:
 The answer is option (4)
Explanation : In the above program, we cant predict the exact order of the output as it is decided by the Thread scheduler which is the part of JVM. 4. What will be the output of the program? Options: 1. Main Run 2. Run Main 3. Compile time error 4. Depend upon JVM Output:
 The answer is option (3)
Explanation : In the above program, we will get compile time error because start() method is present in the Thread class only and we are implementing Runnable interface. 5. What will be the output of the program?
Options: 1. Run 2. Main 3. Compile time error 4. Run Main Output:
 The answer is option (2)
Explanation : In the above program, we are calling start() method of Thread class which is responsible to execute run() method of Thread class and Thread class run() method has empty implementation. That's why one child thread will be created but it will not execute Test class run() method.
Comment
Article Tags: