C. A ParseException is thrown by the parse method at runtime.
D. A NumberFormatException is thrown by the parse method at runtime.
Answer: B
f cannot be resolved to a variable
Consider the following block of statements
Which statement is true if a ResourceException is thrown on line 6?
A. Line 9 will not execute.
B. The connection will not be retrieved in line 2.
C. The resource connection will not be closed on line 5.
D. The enclosing method will throw an exception to its caller.
Answer: C
Consider the following block of statement?
Under which three circumstances will the code on line 7 be executed? (Choose three.)
A. The instance gets garbage collected.
B. The code on line 3 throws an exception.
C. The code on line 5 throws an exception.
D. The code on line 1 throws an exception.
E. The code on line 3 executes successfully.
Answer: B, C, E
Given the program
What is the result?
A. Exception
B. A,B,Exception
C. Compilation fails because of an error in line 16.
D. Compilation fails because of an error in line 8.
E. A NullPointerException is thrown at runtime.
Answer: D
Exception IOException is not compatible with throws clause in A.process()
What is the output of following program?
A. end
B. Compilation fails.
C. exception end
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main
.
Answer: E
What is the output of following program?
A. Compilation fails.
B. pi is bigger than 3.
C. An exception occurs at runtime.
D. pi is bigger than 3. Have a nice day.
E. pi is not bigger than 3. Have a nice day.
Answer: A
Syntax error on token "finally", delete this token
What is the output of following program?
A. test
B. Exception
C. Compilation fails.
D. NullPointerException
Answer: C
Unreachable catch block for NullPointerException. It is already handled by the catch block for Exception
What is the output of following program?
A. test end
B. Compilation fails.
C. test runtime end
D. test exception end
E. A Throwable is thrown by main at runtime.
Answer: D
Given the program
What is the result if a NullPointerException occurs on line 34?
A. c
B. a
C. ab
D. ac
E. bc
F. abc
Answer: D
What is the output of following program?
A. java.lang.StackOverflowError
B. java.lang.IllegalStateException
C. java.lang.ExceptionInInitializerError
D. java.lang.ArrayIndexOutOfBoundsException
Answer: C
Given the program
what is the output?
A. null
B. finally
C. null finally
D. Compilation fails.
E. finally exception
Answer: E
Given the program
Which two are true? (Choose two.)
A. Class A will not compile.
B. Line 16 can throw the unchecked exception TestException.
C. Line 15 can throw the unchecked exception TestException.
D. Line 16 will compile if the enclosing method throws a TestException.
E. Line 16 will compile if enclosed in a try block, where TestException
is caught.
Answer: DE
Given the program
Which, inserted independently at // insert code here, will compile, and produce the output? (Choose all that apply.)
A. String doFileStuff() { return "b"; }
B. String doFileStuff() throws IOException { return "b"; }
C. String doFileStuff(int x) throws IOException { return "b"; }
D. String doFileStuff() throws FileNotFoundException { return "b"; }
E. String doFileStuff() throws NumberFormatException { return "b"; }
F. String doFileStuff() throws NumberFormatException,
FileNotFoundException { return "b"; }
Answer:
-> A , D, E, and F are correct. It’s okay for an overriding method to throw the same
exceptions, narrower exceptions, or no exceptions. And it’s okay for the overriding
method to throw any runtime exceptions.
-> B is incorrect, because the overriding method is trying to throw a broader exception.
C is incorrect. This method doesn’t override, so the output is a.
Given the program
And the command-line invocations:
java Input
java Input 0
Which are true? (Choose all that apply.)
A. Line 6 is executed exactly 0 times.
B. Line 6 is executed exactly 1 time.
C. Line 6 is executed exactly 2 times.
D. The finally block is executed exactly 0 times.
E. The finally block is executed exactly 1 time.
F. The finally block is executed exactly 2 times.
G. Both invocations produce the same exceptions.
H. Each invocation produces a different exception.
Answer:
-> A , F, and H are correct. Since both invocations throw exceptions, line 6 is never reached. Since both exceptions occurred within a try block, the finally block will always execute. The first invocation throws an ArrayIndexOutOfBoundsException, and the second invocation throws an ArithmeticException for the attempt to divide by zero.
-> B, C, D, E, and G are incorrect based on the above.
Given the program
What is the result?
A. -
B. -c
C. -c2
D. -2c
E. -c22b
F. -2c2b
G. -2c2bc
H. Compilation fails.
Answer:
-> B is correct. Once s3() throws the exception to s2(), s2() throws it to s1(), and no
more of s2()’s code will be executed.
-> A, C, D, E, F, G, and H are incorrect based on the above.
Given:
try { int x = Integer.parseInt("two"); }
Which could be used to create an appropriate catch block? (Choose all that apply.)
A. ClassCastException
B. IllegalStateException
C. NumberFormatException
D. IllegalArgumentException
E. ExceptionInInitializerError
F. ArrayIndexOutOfBoundsException
Answer:
-> C and D are correct. Integer.parseInt can throw a NumberFormatException, and IllegalArgumentException is its superclass (i.e., a broader exception).
-> A, B, E, and F are not in NumberFormatException’s class hierarchy.
Given the program
And the following three possible changes:
C1. Declare that main() throws an Exception.
C2. Declare that Ping.getInt() throws an Exception.
C3. Wrap the invocation of getInt() in a try / catch block.
Which change(s) allow the code to compile? (Choose all that apply.)
A. Just C1 is sufficient.
B. Just C2 is sufficient.
C. Just C3 is sufficient.
D. Both C1 and C2 are required.
E. Both C1 and C3 are required.
F. Both C2 and C3 are required.
G. All three changes are required.
Answer:
-> A and C are correct. Remember that line 4 is making a polymorphic call so the compiler knows that an exception might be thrown. If C1 is implemented the exception has been sufficiently declared, and if C3 is implemented the exception has been sufficiently handled. C2 is not necessary in either case.
-> B, D, E, F, and G are incorrect based on the above.
Given the program
What is the result?
A. -ic of
B. -mf of
C. -mc mf
D. -ic mf of
E. -ic mc mf of
F. -ic mc of mf
G. Compilation fails.
Answer:
-> E is correct. There is no problem nesting try / catch blocks. As is normal, when an exception is thrown, the code in the catch block runs, then the code in the finally block runs.
-> A, B, C, D, and F are incorrect based on the above.
Given the program
And the command-line invocation:
java Miner.java
What is the result?
A. null
B. null null
C. A ClassCastException is thrown.
D. A NullPointerException is thrown.
E. A NoClassDefFoundError is thrown.
F. An ArithmeticException is thrown.
G. An IllegalArgumentException is thrown.
H. An ArrayIndexOutOfBoundsException is thrown.
Answer:
-> B is correct. The invocation should be java Miner, in which case null null would be produced.
-> A, C, D, E, F, G, and H are incorrect based on the above.
Which are most typically thrown by an API developer or an application developer as opposed to being thrown by the JVM? (Choose all that apply.)
A. ClassCastException
B. IllegalStateException
C. NumberFormatException
D. IllegalArgumentException
E. ExceptionInInitializerError
Answer:
-> B , C, and D are correct. B is typically used to report an environment problem such as trying to access a resource that’s closed. C is often thrown in API methods that attempt
to convert poorly formed String arguments to numeric values. D is often thrown in API
methods that receive poorly formed arguments.
-> A and E are thrown by the JVM.
I have over 7+ years of experience as a technical lead and have worked at both small startups and large organizations. While I'm a proficient full-stack developer, my expertise is in building scalable backend micro-services (API, Services, Data processing, async processing, multi-threaded services and data analysing) and build the client side UI (single page angular/react applications, Multiplatform rendering using bootstrap or material).
No comments:
Post a Comment