wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception" Watch "Exception" New topic


prasanna perera

Joined: Oct 05, 2000
Posts: 16
Hi All!
This question is from Valiveru's mock exam
Question 37.
Given that method aMethod() throws BaseException, SubException and RuntimeException of the following exception hierarchy
+ - - BaseException
+ - - SubException
+ - - java.lang.RuntimeException

Which of the following are legal

A.public class MyClass {
public void myMethod(){
B.public class MyClass{
public void myMethod() throws BaseException,RuntimeException{
C.public class MyClass{
public void myMethod() throws BaseException{
D.public class MyClass{
public void myMethod() throws Exception{
E.public class MyClass{
public void myMethod() throws RuntimeException {
given ans: c,d
I think b is also correct ?
Harry Singh
Ranch Hand

Joined: Sep 22, 2000
Posts: 53
I would think only D is correct. You really dont have to declare a throws for runtime exceptions.
B does not throw SubException so that would be a compile time error since it is a checked excetion.
Same reasoning for C too.
Can anyone back me up ?
Dev Prakash

Joined: Oct 09, 2000
Posts: 28
I also think that b,c,d are correct. Because in option b it throws BaseException which is the Parent of SubException.
Bin Zhao
Ranch Hand

Joined: Oct 04, 2000
Posts: 73
I have tried the code.
yes, b,c and d are all right.
I agree. Here's the link: http://aspose.com/file-tools
subject: Exception
It's not a secret anymore!