Given the code fragment: What is the result? A. B. Compilation fails only at line n1. C. Compilation fails only at line n2. D. Compilation fails only at line n3. E. Compilation fails at both line n2 and line n3.
Answer is C. Compilation fails only at line n2.
\\Code
public class Test {
void readCard(int cardNo) throws Exception {
System.out.println("Reading Card");
}
void checkCard(int cardNo) throws RuntimeException {
System.out.println("Checking Card");
}
public static void main(String[] args) {
Test ex = new Test();
int cardNo = 12344;
ex.readCard(cardNo);
ex.checkCard(cardNo);
}
}
Answer is C
A, compile error (Does not print)
B, The method itself is not wrong, you just have to try/catch
C, Did not catch the Exception
D, Last line won't fail because it's method is runtime and runtime doesn't happen if it doesn't even compile.
Answer is C. Checked Exceptions should be handled or declared, in this case the problem is that we missed to declare the Exception in main method. So in order your code to pass the compilation, you should add at the main method "throws Exception".
This section is not available anymore. Please use the main Exam Page.1z0-808 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
RoxyFoxy
Highly Voted 2 years, 7 months agosurya8833
Most Recent 4 weeks agoTheeOne
3 months, 1 week agoTheeOne
3 months, 1 week agoMPignaProTech
6 months agojoeMP
6 months, 3 weeks agoz24134
1 year, 6 months agoyefiw
1 year, 6 months agoarjunrawatirissoftware
1 year, 6 months agoDriftKing
1 year, 8 months agoduydn
1 year, 8 months agoa_really_reliable_programmer
1 year, 8 months agoSreeni_A
1 year, 8 months agojlicini
1 year, 9 months agodsms
1 year, 9 months agobilly_the_kid
1 year, 11 months agoVicky_65
2 years, 1 month ago