wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Error/AssertionError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Error/AssertionError " Watch "Doubt in Error/AssertionError " New topic

Doubt in Error/AssertionError

Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
For the following code:

What is the result?
A. end
B. Compilation fails.
C. exception end
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main.

Answer: E

output is:

Doubt: According to the answer, option E, I don't see ant Throwable thrown by main(). Is the option E wrong? Please help
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
AssertionError extends Error that extends Throwable.
So when AssertionError is thrown by main can also be said as
Error is thrown by main or
Throwable is thrown by main.
Hope that clears.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

Gitesh, when you copy a question from a book or mock exam, you need to quote your sources.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Deepak Chopra
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Do Remember the following hirerachy :

or you can say that
Object ----> Throwable ----> Error

So if an instance of type Error is thrown then throwable can catch that, but
Exception can not.

Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
I agree. Here's the link: http://aspose.com/file-tools
subject: Doubt in Error/AssertionError
It's not a secret anymore!