aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg. Exception : Valiverus' exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reg. Exception : Valiverus Watch "Reg. Exception : Valiverus New topic
Author

Reg. Exception : Valiverus' exam

Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327

Given that method aMethod() throws BaseException, SubException and RuntimeException of the following exception hierarchy
java.lang.Exception
|
+ - - BaseException
|
+ - - SubException
|
+ - - java.lang.RuntimeException

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
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
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).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
Hello Jane,
Actually the "SubException" is immediate subclass
of "BaseException" class as corrected below
java.lang.Exception
|
+-- BaseException
  |
�   +-- SubException

+-- java.lang.RuntimeException

[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).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Reg. Exception : Valiverus' exam