This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I chose java.lang.Exception-- all Exceptions are subclasses of this one. The offical answer, java.lang.Throwable comes with a comment (which is true!) "The Exception hierarchy begins at java.lang.Throwable."
That's true, but I didn't interpret the original question as "Where does the Exception hierarchy begin?" or I would have chosen java.lang.Throwable. Am I way off here?
For a significant number of questions (on every exam prep, not just in the Round-up), it seems there is an easy answer and a tricky answer (especially for true/false), but it's not consistent which one is the one to choose. I'll post better examples of this when I run into other instances.
I suppose the question is, does Exception itself inherit from Exception? That depends on your definition of "inherit". Some might argue that a class inherits from itself. OK. But a careful reading of the Java Language Specification indicates that, as used in the Java programming language, a class does not inherit from itself. So according to the JLS, your interpretation is incorrect.
More pragmatically, according to your interpretation there should be two correct answers, yes? Both Exception and Throwable would work. So - how many answers does the question allow you to provide? If the question allows multiple responses, then maybe you should answer both Exception and Throwable. (I wouldn't, for the a reasons given in my first paragraph, but maybe you diesagree...) But if the question allows only one answer (as is the case in the rules roundup, I think) then you need to decide - what is the best answer? Exception, which is true only if you interpret "inherit" a certain way? Or Throwable, which is always, inarguably, true? Dunno about you, but I know which one I'd choose...
The actual SCJP exam exam will almost certainly tell you how many answers to pick, if more than one answer is expected. Which makes things easier - you just need to focus on what is the best answer (or best N answers). Many mock exams are not written this way, so you may be getting the wrong idea about what actual exam questions are like. (In the past, exam questions were written differently than they are nowadays.) So don't worry too much about this issue - just concentrate on learning how Java works.
Hi, I'll post a simple and easy example for your question. Do you know that the class Exception it self os an exception. That we can throw just Exception. So now you are saying that all the exceptions inherit from(are subclasses of)the class Exception. Due to my knowledge a class can't extend itself. I think you understand now.