Which two actions, used independently, will permit this class to compile?

Given:

import java.io.IOException;
public class Y {
public static void main(String[] args) {
try {
doSomething();
}
catch (RuntimeException e) {
System.out.println(e);
}
}
static void doSomething() {
if (Math.random() > 0.5) throw new IOException();
throw new RuntimeException();
}
}

Which two actions, used independently, will permit this class to compile?

Given:

import java.io.IOException;
public class Y {
public static void main(String[] args) {
try {
doSomething();
}
catch (RuntimeException e) {
System.out.println(e);
}
}
static void doSomething() {
if (Math.random() > 0.5) throw new IOException();
throw new RuntimeException();
}
}

Which two actions, used independently, will permit this class to compile?

A.
Adding throws IOException to the main() method signature

B.
Adding throws IOException to the doSoomething() method signature

C.
Adding throws IOException to the main() method signature and to the dosomething() method

D.
Adding throws IOException to the dosomething() method signature and changing the catch argument to IOException

E.
Adding throws IOException to the main() method signature and changing the catch argument to IOException

Explanation:
The IOException must be caught or be declared to be thrown. We must add a throws exception to the doSomething () method signature (static void doSomething() throws IOException).
Then we can either add the same throws IOException to the main method (public static void main(String[] args) throws IOException), or change the catch statement in main to IOException.



Leave a Reply 6

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


Abed Abu Alhalawa

Abed Abu Alhalawa

C , D

James

James

The Answer is C, D.

surfo

surfo

Las respuestas son A y B

Martin Lee

Martin Lee

Hi, I have passed OCAJP 7 (1Z0-803) EXAM with 98%. I would like to share my exam experience with those who are going to take this exam. I learned the Mala Gupta’s book and PassLeader 1Z0-803 dumps. They were describing and explaning the key points of the exam very clearly. To be honest, I read Mala Gupta’s book mainly because of the interest how the basic things in Java are handled internally and I started to take the PassLeader 1Z0-803 dumps (http://www.passleader.com/1z0-803.html), around one week before the exam. Good luck to future Oracle exam takers!

Mongikazi

Mongikazi

Hi Martin Lee

Thank you for the information,i will writing java soon do you still have those PassLeader Dumps ? and send it to me if you can please, the thing is I do not have money to buy them, thank you in advance.

Kind Regards
Mongikazi Kala