Question: What is wrong with the following code? Select the one correct answer. (a) The main() method must declare that it throws B. (b) The finally

What is wrong with the following code?

public class RQ6A20 { public static void main(String [] args) throws A

Select the one correct answer.

(a) The main() method must declare that it throws B.

(b) The finally clause must follow the catch clause in the main() method.

(c) The catch clause in the main() method must declare that it catches B rather than A.

(d) A single try block cannot be followed by both catch and finally clauses.

(e) The declaration of class A is illegal.

public class RQ6A20 { public static void main(String [] args) throws A { try { action(); } finally { System.out.println ("Done."); } catch (A e) { throw e; } public static void action () throws B { throw new B(); } class A extends Throwable {} class B extends A {}

Step by Step Solution

3.32 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

b The only thing that is wrong with ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming 8th Questions!