Welcome Guest | Sign in | Register
Exceptions - Discussion Page For Q.2639 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Exceptions > Questions and Answers

Q: 1 class TestException extends Exception { }
2 class A {
3 public String sayHello(String name) throws TestException {
4 if(name == null) throw new TestException();
5 return "Hello " + name; }
6 }
7 public class TestA {
8 public static void main(String[] args) {
9 new A().sayHello("Aiko");
10 } }
A. Compilation succeeds. B. Class A does not compile
C. The method declared on line 9 cannot be modified to throw TestException. D. TestA compiles if line 9 is enclosed in a try/catch block that catches TestException.

Answer and Explanation

Answer:TestA compiles if line 9 is enclosed in a try/catch block that catches TestException.

Explanation:
From class A there is a method sayHello() which is throwing an exception. From main ( ) when we call that sayHello() it should be enclosed with try block.
So D) is correct.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.