What is the output of the following code? class Shared { syn…
What is the output of the following code? class Shared { synchronized void print() { System.out.println(“Printing…”); } } public class Test extends Thread { Shared s; Test(Shared s) { this.s = s; } public void run() { s.print(); } public static void main(String[] args) { Shared obj = new Shared(); Test t1 = new Test(obj); Test t2 = new Test(obj); t1.start(); t2.start(); } }
Read DetailsWhat is the output? public class Example { public static voi…
What is the output? public class Example { public static void main(String[] args) throws InterruptedException { Thread t = new Thread(() -> { try { Thread.sleep(2000); System.out.println(“Hello”); } catch (InterruptedException e) { System.out.println(“Interrupted”); } }); t.start(); t.join(); System.out.println(“World”); } }
Read DetailsWhat will be the output of the following code? class MyThre…
What will be the output of the following code? class MyThread extends Thread { public void run() { System.out.print(“A “); } public static void main(String[] args) { MyThread t = new MyThread(); t.run(); System.out.print(“B “); } }
Read DetailsWhat is the output of the following program? public class De…
What is the output of the following program? public class Demo extends Thread { public void run() { try { System.out.println(“Thread started”); Thread.sleep(1000); System.out.println(“Thread resumed”); } catch (InterruptedException e) { System.out.println(“Interrupted”); } } public static void main(String[] args) { Demo t = new Demo(); t.start(); t.interrupt(); } }
Read Details