Which statement is true? A. catch(X x) can catch subclasses of X. B. The Error class is a RuntimeException. C. Any statement that can throw an Error must be enclosed in a try block. D. Any statement that can throw an Exception must be enclosed in a try block. E. Any statement that can throw a RuntimeException must be enclosed in a try block.
here optian A and D seems to be the correct ans. but i cant figure out the one which is right.
Please revise your display name to meet the JavaRanch Naming Policy. You've been asked twice before in previous posts -- and we take this policy seriously. You can edit your name here.
Thank you for your prompt attention!
Now, as to the question...
D. Any statement that can throw an Exception must be enclosed in a try block.
Consider that an unchecked RuntimeException is an Exception, so D is false. Furthermore, even a statement that throws a checked Exception does not need to be in a try block if its enclosing method declares the Exception.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org