How do I throw an exception when I receive a signal?

Java Exception Help!!!?

  • 11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println("B"); } 16. } 17. public static void main(String[] args) { 18. new B().process(); 19. } What is the result? A. B B. The code runs with no output. C. Compilation fails because of an error in line 12. D. Compilation fails because of an error in line 15. E. Compilation fails because of an error in line 18. the Answer given is A How is it possible as the thrown exception in line12 is not caught anywhere.the how can it run without any exception??

  • Answer:

    Exception is thrown in superclass method which is never called.. you are only calling overriding method in subclass which doesnt throw any error or exception..

Krithika at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

No exception is thrown when this is executed, because the process() method in the A class is never called. Only the process() method in the B class is called.

Silent

To be bit more explanatory..... compiler first looks for the method in the same class , if it is found then that is called else it goes up in the hierarchy i.e in superclass and call the method in superclass... So as the method is found locally in B there is no need to search it in A

Rooney

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.