THREAD & CONCURRENCY

Questions no -4 What is the output for the below code ?

public class Test extends Thread{
    public static void main(String argv[]){
        Test  b = new Test();
        b.start();
    }
    public void run(){     
        System.out.println("Running");
    }
}

A)Compilation clean and run but no output
B)Compilation and run with the output "Running"
C)Compile time error with complaint of no Thread import
D)Compile time error with complaint of no access to Thread package

Answer 4: B
The Thread class is part of the core java.lang package and does not need any explicit import statement.


Questions no -5 What is the output for the below code ?

class A extends Thread {
public void run() {
System.out.print("A");
}
}
class B {
public static void main (String[] args) {
A a = new A();
a.start();
a.start();  // 1
}
}

A)compile time error
B)Runtime Exception
C)the code compile and runs fine
D)none of the above

Answer 5: B
If the start method is invoked on a thread that is already running, then an IllegalThreadStateException will probably be thrown