What is the result?
A.
Null
B.
class java.lang.ArraylndexOutOfBoundsException
C.
class java.lang.NullPointerException
D.
class java.lang.Exception
E.
Compilation fails.
Explanation:
error: incompatible types
e = new Exception();
required: RuntimeException
found: Exception
E. According to Oracle Java Documentation:
“If a catch block handles more than one exception type, then the catch parameter is implicitly final.”
In this example, the catch parameter e is final and therefore we cannot assign any values to it within the catch block.
It should be a
No should be A
I mean should be E, not A
E
Variable e is final. E is corect.
Multiple catch is final and Incompatible type of e
Sorry, the wording should be multi-catch parameter e may not be assigned.
E.
e = new Exception();
“Type mismatch: cannot convert from Exception to RuntimeException”
e = new ArrayIndexOutOfBoundsException();
With a RuntimeException the compiler says:
“The parameter e of a multi-catch block cannot be assigned”