What is the result?

Given the following code for the classes MyException and Test: What is the result?

Given the following code for the classes MyException and Test: What is the result?

A.
A

B.
B

C.
Either A or B

D.
A B

E.
A compile time error occurs at line n1



Leave a Reply 16

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


Josh

Josh

B seems correct

szczwp

szczwp

Yeap B is correct (most of the answers in this dump are incorrect)

Bob

Bob

You’re wrong. A few questions on this dump might be incorrect, but the vast and enormously large portion of the answers are indeed correct. I’ve verified them with Pass4Sure and 2 other dumps.

Pooja

Pooja

Hi Bob,

Please send me dump of Pass4Sure on [email protected]
i’m going to write an exam 1z0-808.

Best Regards,
Pooja

Kaykay

Kaykay

Definitely B.

Both are RuntimeExceptions.

JavaNooB

JavaNooB

Assume class MyException and class Test are at 2 different java files.
Cannot have 2 public class at one same java file.

Tomas

Tomas

Answer: B
Tested

Arend

Arend

Well, sometimes it prints B

package Exceptions;

public class MyException extends RuntimeException {
}

package Exceptions;

public class Test {

public static void main(String[] args) {
try {
method1();
} catch (MyException ne) {
System.out.println(“A”);
}
}

public static void method1() {
try {
throw Math.random() > 0.5 ? new MyException() : new RuntimeException();
} catch (MyException re) {
System.out.println(“B”);
}
}
}

Console:
B

And sometimes i get RuntimeException when the random number is above 0.5

Console:
Exception in thread “main” java.lang.RuntimeException
at Exceptions.Test.method1(Test.java:15)
at Exceptions.Test.main(Test.java:7)

Arend

Arend

Correction:

(option 1)catch (MyException re) => (option 2)catch (RuntimeException re)