Java Thread Program Practice Test-2

What will be the output of the following java code?

public class Test implements Runnable {

public void run() {

System.out.print("thread");

}

public static void main(String[] args) {

Thread t = new Thread(new Test());

t.run();

t.run();

t.start();

}

}

What will be the output of the following java code?

public class Test {

public void hello() {

Runnable r = new Runnable() {

public void run() {

System.out.println("welcome");

}

};

Thread th = new Thread(r);

th.start();

th.start();

}

public static void main(String[] args) {

new Test().hello();

}

}

What will be the output of the following java code?

public class Test {

public static void main(String[] args) {

new Thread(new Runnable() {

public void run() {

System.out.println("multithread");

}

}).start();

}

}

What will be the output of the following java code?

public class Test {

public static void main(String[] args) {

Runnable r = new Runnable() {

public void run() {

System.out.println("java");

}

};

Thread t = new Thread(r) {

public void run() {

System.out.println("spring");

}

};

t.start();

}

}

What will be the output of the following java code?

public class Test implements Runnable {

public void run() {

System.out.println("thread");

throw new RuntimeException("exception occured");

}

public static void main(String[] args) {

Thread t = new Thread(new Test());

t.start();

System.out.println("main");

}

}