Essay on The Republic Day | Republic Day Essay in English
[ Festival Ganesh Chaturthi Essay in English for Students and Children ] [ Essay on my favourite freedom fighter ] ⚔️ [ दुर्गा पूजा पर निबंध (Durga Puja Hindi Essay) ]
[Essay On 75th Independence Day Of India] [Azadi Ka Amrit Mahotsav Essay in English]

What will be the output of the program?


			  		

Loading

Practice Threads –

What will be the output of the program?

public class Test107 implements Runnable  {     
private int x;
private int y;
public static void main(String args[]) {
Test107 that = new Test107();
(new Thread(that)).start();
(new Thread(that)).start();
}
public synchronized void run() {
for(int i = 0; i < 10; i++) {
x++;
y++;
System.out.println("x = " + x + ", y = " + y); /* Line 17 */
}
}
}

 

What will be the output of the program?


			  		

Loading

Practice Threads –

What will be the output of the program?

class s1 implements Runnable {      
int x = 0, y = 0;
int addX() {
x++;
return x;
}
int addY() {
y++;
return y;
}
public void run() {
for(int i = 0; i < 10; i++)
System.out.println(addX() + " " + addY());
}
public static void main(String args[]) {
s1 run1 = new s1();
s1 run2 = new s1();
Thread t1 = new Thread(run1);
Thread t2 = new Thread(run2);
t1.start();
t2.start();
}
}

 

What will be the output of the program?


			  		

Loading

Practice Threads –

What will be the output of the program?

class MyThread extends Thread {      
MyThread() {
}
MyThread(Runnable r) {
super(r);
}
public void run() {
System.out.print("Inside Thread ");
}
}
class MyRunnable implements Runnable {
public void run() {
System.out.print(" Inside Runnable");
}
}
class Test {
public static void main(String[] args) {
new MyThread().start();
new MyThread(new MyRunnable()).start();
}
}

 

What will be the output of the program?


			  		

Loading

Practice Threads –

What will be the output of the program?

class MyThread extends Thread {
MyThread() {
System.out.print(" MyThread");
}
public void run() {
System.out.print(" bar");
}
public void run(String s) {
System.out.println(" baz");
}
}
public class TestThreads {
public static void main (String [] args) {
Thread t = new MyThread() {
public void run() {
System.out.println(" foo");
}
};
t.start();
}
}