Question: Java NetBeans project ***please show solution**** public class JavaApplication1 { public static void main(String[] args) { RuntimeException exception = null; throw exception; } } Test

Java NetBeans project ***please show solution****

public class JavaApplication1 {

public static void main(String[] args) {

RuntimeException exception = null;

throw exception;

}

}

Test Stem / Question

Choices

What is the problem with the above code?

A: null exception cannot be thrown

B: the main method must be declared with throws statement

C: It is illegal to throw an exception

D: Nothing is wrong

How should you fix the code? Choose from the following:

  1. Instantiate the exception
  2. Add a throws statement in the method declaration
  3. Do no throw the exception

A: A & B

B: A only

C: B only

D: All is correct

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!