File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reg. Exception : Valiverus' exam

 
Angela Narain
Ranch Hand
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 346
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 (/^_^\)
 
Jane Griscti
Ranch Hand
Posts: 3141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Angela Narain
Ranch Hand
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic