permaculture playing cards*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Author

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
Hello

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
Greenhorn

Joined: Sep 26, 2007
Posts: 10
Because

makes the compiler complain that there is an

in line 4.
Regards,
Matthias
Justin Russo
Ranch Hand

Joined: Oct 21, 2007
Posts: 77
Thanks!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on K& B chapter 5.
 
Similar Threads
An Exception Problem
Overridden method and exceptions
chapter 5,question-8,(k&b)
K&B Chapter 5 Self-test Question #8
Overriden method throwing Exception.