• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on K& B chapter 5.

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because

makes the compiler complain that there is an

in line 4.
Regards,
Matthias
 
Justin Russo
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!!
 
Every plan is a little cooler if you have a blimp. And a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic