Menu
Question Index
...

What will be the output of the following program?

public class WorkingWithThread extends Thread {
    String str = "";
    public WorkingWithThread(String s) {    str = s;    }
    public void run() {
        if (str.equals("thread1") | str.equals("thread2")) {
            yield();
            System.out.println("End of " + str);
        }
    }
    public static void main(String args[]) {
        Thread thread1 = new WorkingWithThread("thread1");
        Thread thread2 = new WorkingWithThread("thread2");
        thread2.setPriority(Thread.MAX_PRIORITY);
        thread1.setPriority(Thread.MIN_PRIORITY);
        thread1.run();
        thread2.run();
    }
}


End of thread1
End of thread2
End of thread2
End of thread1
Some other output
Output can not be determined
Compilation Error or Runtime Error

Doubts

Problems

Topic: What is Multitasking and Multithreading?

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App