Interview Questions

Output question 22.

Java Interview Questions and Answers (part 4)


(Continued from previous question...)

82. Output question 22.

public class MyClass {
public static void main(String[] args) {
System.out.println("1 ");
InnerClass i=new InnerClass();
i.start();
System.out.println("2 ");
}

static class InnerClass extends Thread{
public void run()throws RuntimeException{
throw new RuntimeException();
}
}
}



Answer.
Program will compile as run() method can throw RuntimeException. 1 and 2 will be present in output and will throw java.lang.RuntimeException at runtime.


/*OUTPUT
1
2
Exception in thread "Thread-0" java.lang.RuntimeException
at o22.s$InnerClass.run(s.java:13)
*/

Other Interview Questions