| Author |
throws RuntimeException
|
Alfred Kemety
Ranch Hand
Joined: Aug 14, 2002
Posts: 279
|
|
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();}} Answer is C, D Why isn't B legal???
|
Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
|
 |
Mocha D'Late
Greenhorn
Joined: Oct 27, 2002
Posts: 11
|
|
Here is my take : the order of the exception classes in throws matters. BaseException is 'broader' than RuntimeException, so need to be in reverse order : public class MyClass{ public void myMethod() throws RuntimeException{ aMethod();}}
|
 |
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
|
|
The order doesn't matter. Furthermore, the following program compiles without error, so B is correct. Why do you say it isn't? [ October 27, 2002: Message edited by: Ron Newman ]
|
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
|
 |
Alfred Kemety
Ranch Hand
Joined: Aug 14, 2002
Posts: 279
|
|
It's not me that say it isn't.. the mock exam at this URL says it isn't.. http://valiveru.tripod.com/java/jvaltest.html One more question, Are objects of java.lang.Math immutable?? Actually are there objects of java.lang.Math?? I know it can't be instantiated, or shall I consider that a Math object can be of actual type Integer or Long and then I can say that objects of java.lang.Math are immutable?? how about java.lang.Object? is it immutable too?
|
 |
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
|
|
You've found an error in that mock exam. I suggest following the instructions at the bottom of that page:
Despite our sincere efforts and thorough scrutiny this mock exam may contain errors, do mail us (valiveru@mail.com) if you find one, mentioning the question and details of the error.
You can't instantiate an object of type Math, so it doesn't really matter whether it is immutable or not. Integer and Long are not subclasses of Math, they are subclasses of Number. I don't think it's meaningful to say that Object is immutable or mutable.
|
 |
Alfred Kemety
Ranch Hand
Joined: Aug 14, 2002
Posts: 279
|
|
|
Ops, missed with Math and Number, but one of the questions was asking which classes are immutable, and Object and Math was in the choices, so I was wondering
|
 |
 |
|
|
subject: throws RuntimeException
|
|
|