Multiple Choice Question

Quiz Guidelines

 

QID: 
252
Question: 

What is wrong with the following code?

class MyException extends Exception {}
public class TestClass{
public static void main(String[] args){
TestClass tc = new TestClass();
try{
tc.m1();
} catch (MyException e){
tc.m1();
} finally{
tc.m2();
}
} public void m1() throws MyException{
throw new MyException();
} public void m2() throws RuntimeException{
throw new NullPointerException();
}
}

Select 1 option

A. It will not compile because you cannot throw an exception in finally block.
B. It will not compile because you cannot throw an exception in catch block.
C. It will not compile because NullPointerException cannot be created this way.
D. It will not compile because of unhandled exception.
E. It will compile but will throw an exception when run.

Q&A Set: 

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!