Please submit one file (HomeWork6.txt) with the answers to the following questions:
1) When do you encounter NullPointerException?(Choose
as many as apply from the options below)
a) When you access item n in an array
of size n (ie a[10] where a.length == 10).
b) When you try to access an object
which has been declared but has not been initialised.
c) When you try to access an
object which has not been declared.
d) When you try to access an
object outside the scope of its declaration.
2-9) Explain the differences between the following pairs
of terms:
a) Throwing an exception and
catching an exception.
b) Try block and catch
block.
c) Catch block and finally
block.
d) Try block and finally
block.
e) Dynamic scope and static scope.
f) Dialog box and top-level window.
g) Checked and unchecked expression.
h) Method stack and method call.
The code for the ExerciseExample class is used in the questions that follow.
public class ExerciseExample{
public void method1(int M){
try {
System.out.println("Entering try block");
method2(M);
System.out.println("Exiting try block");
} catch(Exception
e) {
System.out.println("ERROR: " + e.getMessage());
}
}
public void method2(int M){
if(M>100)
throw new ArithmeticException(M + " is too large");
}
public static void main(String[]
s){
ExerciseExample
ex = new ExerciseExample();
ex.method1(500);
}
}
10-11) What would be printed by the ExampleExercise program when it is run?
12-13) What would be printed by the ExampleExercise program, if the statement in its main method were changed to ex.method1(5)?
14-15) Do problem 15, p. 649, assuming that a number outside the bound is entered. Turn in only what prints as a result, not the code itself.