This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on K& B chapter 5. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on K& B chapter 5." Watch "Question on K& B chapter 5." New topic

Question on K& B chapter 5.

Justin Russo
Ranch Hand

Joined: Oct 21, 2007
Posts: 77

three possible changes
C1. Declare the main() throws an Exception
C2. Declare the Ping.getInt() throws an Exception
C3. Wrap the invocation of getInt() in try / catch block.

which change(s) allow the code to compile (choose all that apply)
A. Just C1 is sufficient
B. Just C2 is sufficient
C. Just C3 is sufficient
D. Both C1 and C2 are required
E. Both C1 and C3 are required
F. Both C2 and C3 are required
G. All three changes are required

Answer was A and C

My question is why B is considered incorrect when the question states that choose all that apply for successfully compilation.
Also the answer in the book states that B is not ncessary so confused..

Please let me know the reason.

thanks a lot!

You Want it.. Get it.......the Right Way...<br /> <br />SCJP 5.0 SCWCD 5.0
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424

Maybe you need to try to compile the program and see which options are required to make successful compile.

However in main method you are invoking(at compile time) a method that might throw a checked Exception.

Either you need to declare that the calling method which is 'main' to throw the Exception, or wrap the method call getInt() in a try/catch block.
Matthias Wendel

Joined: Sep 26, 2007
Posts: 10

makes the compiler complain that there is an

in line 4.
Justin Russo
Ranch Hand

Joined: Oct 21, 2007
Posts: 77
jQuery in Action, 2nd edition
subject: Question on K& B chapter 5.
Similar Threads
Overriden method throwing Exception.
K&B Chapter 5 Self-test Question #8
An Exception Problem
Overridden method and exceptions
chapter 5,question-8,(k&b)