Thursday 21 February 2013

15. What is the result when you compile and run the following code?

15. What is the result when you compile and run the following code?

Choices:
a. Compilation error
b. Runtime error
c. Compile successfully, nothing is printed.
d. Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo

Answer:-
A is correct.
Exception :java.lang.IllegalAccessExcption must be caught or placed in the throws clause of the throwMethod(), i.e. the declaration of throwMethod() be changed to "static void throwMethod() throws IllegalAccessExcption". Thus compilation error will occur.

No comments:

Post a Comment