InterviewSolution
| 1. |
What Is The Output Of This Program? 1. Class Newthread Implements Runnable { 2. Thread T1,t2; 3. Newthread() { 4. T1 = New Thread(this,"thread_1"); 5. T2 = New Thread(this,"thread_2"); 6. T1.start(); 7. T2.start(); 8. } 9. Public Void Run() { 10. T2.setpriority(thread.max_priority); 11. System.out.print(t1.equals(t2)); 12. } 13. } 14. Class Multithreaded_programing { 15. Public Static Void Main(string Args[]) { 16. New Newthread(); 17. } 18. } |
|
Answer» Threads t1 & t2 are created by class newthread that is implementing runnable INTERFACE, hence both the threads are provided their own run() METHOD specifying the actions to be taken. When constructor of newthread class is called first the run() method of t1 executes than the run method of t2 printing 2 times “false” as both the threads are not equal one is having different priority than other, hence FALSEFALSE is printed. Output: $ javac multithreaded_programing.java Threads t1 & t2 are created by class newthread that is implementing runnable interface, hence both the threads are provided their own run() method specifying the actions to be taken. When constructor of newthread class is called first the run() method of t1 executes than the run method of t2 printing 2 times “false” as both the threads are not equal one is having different priority than other, hence falsefalse is printed. Output: $ javac multithreaded_programing.java |
|