Q16
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
Adding throws IOException to the main() method signature
B.
Adding throws IOException to the doSoomething() method signature
Adding throws IOException to the doSoomething() method signature
C.
Adding throws IOException to the main() method signature and to the dosomething() method
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
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
Risposta : C e D :
Adding throws IOException to the main() method signature and changing the catch argument to IOException
Risposta : C e D :
|
public static void main(String[] args) throws IOException {
try {
doSomething();
} catch
(RuntimeException e) {
System.out.println(e);
}
}
static void doSomething() throws IOException {
if (Math.random()
> 0.5)
throw new IOException();
throw new RuntimeException();
}
|
public static void main(String[] args) {
try {
doSomething();
} catch (IOException
e) {
System.out.println(e);
}
}
static void doSomething() throws IOException {
if (Math.random()
> 0.5)
throw new
IOException();
throw new
RuntimeException();
}
|
Nessun commento:
Posta un commento