What will be the output of the following java code?
public class Test extends Thread {
public void run() {
for (int i = 0; i < 3; i++) {
System.out.println(i);
}
}
public static void main(String[] args) throws RuntimeException {
Test t = new Test();
System.out.println("Start");
t.start();
try {
t.join();
} finally {
System.out.println("join");
}
System.out.println("End");
}
}
What will be the output of the following java code?
public class Test {
private int m;
public void check() {
int a = m;
m = a + 1;
}
public void hello() {
for (int i = 0; i < 3; i++) {
new Thread() {
public void run() {
check();
System.out.print(m + ",");
}
}.start();
}
}
public static void main(String[] args) {
Test t=new Test();
t.hello();
}
}
What will be the output of the following java code?
public class Test {
public static void main(String[] args) {
try {
System.out.print("start,");
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print("end");
}
}
What will be the output of the following java code?
class Hello extends Thread {
public void run() {
System.out.println("Thread Start");
}
}
public class Test {
public static void main(String[] args) {
Hello h = new Hello();
h.start();
for (int i = 0; i < 2; i++) {
if (i == 1) {
int k = 10 / 0;
}
}
System.out.println("End");
}
}
What will be the output of the following java code?
public class Test {
public static void main(String[] args) {
new Test().hello();
}
public void hello() {
new Thread() {
public void run() {
System.out.println("welcome");
}
}.start();
Thread t = new Thread();
t.start();
}
}