Which of the following are legal A.public class MyClass { public void myMethod(){ aMethod(); } } B.public class MyClass{ public void myMethod() throws BaseException,RuntimeException{ aMethod(); } } C.public class MyClass{ public void myMethod() throws BaseException{ aMethod(); } } D.public class MyClass{ public void myMethod() throws Exception{ aMethod(); } } E.public class MyClass{ public void myMethod() throws RuntimeException { aMethod(); } }
What are the correct answers ? I assume B, C, D
Gagan Indus
Ranch Hand
Joined: Feb 28, 2001
Posts: 346
posted
0
i agree B , C & D are correct A)myMethod() isn't catching any exceptions , so it must declare them in throws E) none of da checked-exception is declared in throws
------------------ Gagan (/^_^\)
Gagan (/^_^\) SCJP2 SCWCD IBM486 <br />Die-hard JavaMonk -- little Java a day, keeps you going.<br /><a href="http://www.objectfirst.com/blog" target="_blank" rel="nofollow">My Blog</a>
Jane Griscti
Ranch Hand
Joined: Aug 30, 2000
Posts: 3141
posted
0
Hi Angela, Based on the way you've drawn the heirarchy, "B" and "C" would also have to throw "SubException" .. unless "SubException" is really a subclass of "BaseException"
------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited September 15, 2001).]
Hello Jane, Actually the "SubException" is immediate subclass of "BaseException" class as corrected below java.lang.Exception | +-- BaseException   | �   +-- SubException
[This message has been edited by Angela Narain (edited September 16, 2001).] [This message has been edited by Angela Narain (edited September 16, 2001).] [This message has been edited by Angela Narain (edited September 16, 2001).]