File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Jxam question 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 "Jxam question" Watch "Jxam question" New topic

Jxam question

Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
I encountered the following question in Jxam.
Suppose a MyException should be thrown if Condition() is true, which statements do you have to insert ? Select all correct Answers
1: public aMethod {
3: if (Condition) {
5: }
7: }
A) throw new Exception() at line 4
B) throws new MyException() at line 4
C) throw new MyException() at line 6
D) throws new Exception() at line 2
E) throws MyException at line 1
My answer was only E).
Jxam says answer is E) & B)
I tested it out with jdk1.3 & got the following result when I plugged in choice B) in the code. illegal start of expression
I think this is probably a typo error by the Jxam developer. There is an additional 's' in the choice B).
The choice B) should read as follows ...
B) throw new MyException() at line 4
- Himanshu

Himanshu Jhamb<br />SCJP2 v1.2 (April 2002)<br />SCJP2 v1.4 (May 2002)
Macon Pegram

Joined: Mar 01, 2002
Posts: 12
It is a typo... B should read:
throw new MyException()
not "throws". "throws" indicates possible exceptions a method may throw (and is used as part of the method definition. "throw" is used to explicitly throw an exception.
I would have agreed with you that only E was correct given the options.
I agree. Here's the link:
subject: Jxam question
It's not a secret anymore!