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:
|
A: A & B |
|
B: A only |
|
|
C: B only |
|
|
D: All is correct |
1) When you run first code following is the out put :
package HomeworkLib;
public class JavaApplication1 {
public static void main(String[] args) {
RuntimeException exception =
null;
throw exception;
}
}

Answer : A) null exception can not be thrown
2)
package HomeworkLib;
public class JavaApplication1 {
public static void main(String[] args) throws
Exception {
RuntimeException exception = new
RuntimeException("new exception");
throw exception;
}
}

Answer :
1) A &B
Java NetBeans project ***please show solution**** public class JavaApplication1 { public static void main(String[] args)...