What is the result?

Given:

What is the result?

Given:

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



Leave a Reply 9

Your email address will not be published. Required fields are marked *


Tim

Tim

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.

Charles

Charles

It should be a

Bahaa Khateib

Bahaa Khateib

No should be A

Bahaa Khateib

Bahaa Khateib

I mean should be E, not A

zdeDu

zdeDu

Variable e is final. E is corect.

test

test

Multiple catch is final and Incompatible type of e

test

test

Sorry, the wording should be multi-catch parameter e may not be assigned.

gelete

gelete

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”