File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

prasanna perera
Greenhorn

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
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();
}
}
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 ?
Thanks
Dev Prakash
Greenhorn

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
 
Similar Threads
Exceptions - Question
Exceptions
throws RuntimeException
Help me friends. I'll appreciate your answer.(Exceptions)
Reg. Exception : Valiverus' exam