READ Free Dumps For Oracle- 1z0-803
Question ID 21925 | Given:
public class DoCompare1 {
public static void main(String[] args) {
String[] table = {"aa", "bb", "cc"};
for (String ss: table) {
int ii = 0;
while (ii < table.length) {
System.out.println(ss + ", " + ii);
ii++;
}}
How many times is 2 printed as a part of the output?
|
Option A | Zero
|
Option B | Once
|
Option C | Twice
|
Option D | Thrice
|
Option E | Compilation fails.
|
Option F | Correct Answer: C
Explanation:
The for statement, for (String ss: table), is executed one time for each of the three elements in table.
The while loop will print a 2 once for each element.
Output:
aa, 0
aa, 1
aa, 2
bb, 0
bb, 1
bb, 2
cc, 0
cc, 1
cc, 2
|
Correct Answer | F |
Explanation
Question ID 21926 | 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?
|
Option A | Adding throws IOException to the main() method signature
|
Option B | Adding throws IOException to the doSoomething() method signature
|
Option C | Adding throws IOException to the main() method signature and to the dosomething() method
|
Option D | Adding throws IOException to the dosomething() method signature and changing the catch argument to
IOException
|
Option E | Adding throws IOException to the main() method signature and changing the catch argument to
IOException
|
Correct Answer | C,D |
Explanation 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.