READ Free Dumps For Oracle- 1z0-804
Question ID 21461 | Given:
class InvalidAgeException extends IllegalArgumentException { }
public class Tracker {
void verify (int age) throws IllegalArgumentException {
if (age < 12)
throw new InvalidAgeException ();
if (age >= 12 && age <= 60)
System.out.print("General category");
else
System.out.print("Senior citizen category");
}
public static void main(String[] args) {
int age = Integer.parseInt(args[1]);
try {
new Tracker().verify(age);
}
catch (Exception e) {
System.out.print(e.getClass());
}
}
}
And the command-line invocation:
Java Tracker 12 11
What is the result?
|
Option A | General category
|
Option B | class InvalidAgeException
|
Option C | class java.lang.IllegalArgumentException
|
Option D | class java.lang.RuntimeException
|
Correct Answer | B |
Explanation Explanation: The second argument 11 makes the program to throw an InvalidAgeException due to the line: if (age < 12) throw new InvalidAgeException ();
Question ID 21462 | Given the code fragment:
static public void infected() {
System.out.print("before ");
try {
int i = 1/0;
System.out.print("try ");
} catch(Exception e) {
System.out.print("catch ");
throw e;
} finally {
System.out.print("finally ");
}
System.out.print("after ");
}
What is the result when infected() is invoked?
|
Option A | before try catch finally after
|
Option B | before catch finally after
|
Option C | before catch after
|
Option D | before catch finally
|
Option E | before catch
|
Correct Answer | D |
Explanation Explanation: D The following line throws and exception: int i = 1/0; This exception is caught by: catch(Exception e) { System.out.print("catch "); throw e; Lastly, the finally statement is run as the finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs. Reference: Java Tutorial,The finally Block