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
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
Related Q & A:
- How to Implement Gateway Service something similar to Oracle API gateway Using Java and Java based Open Source frameworks only?Best solution by Quora
- How to handle exception in Java?Best solution by javatpoint.com
- I need help with writing up the Java Code.Best solution by Yahoo! Answers
- My FedEx tracking update says delivery exception what does it mean?Best solution by Yahoo! Answers
- How do you add Facebook as an exception in your pop-up blocker preferences?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.