• 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

K&B Book,chapter 5

 
Ranch Hand
Posts: 74
Netbeans IDE Tomcat Server Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In page 415 there's this code



class CC5 extends CC,but doesn't declare or handle the exception inherited from CC,and yet answer E is incorrect??!!

can someone give me some insight on this please?

thanks in advance
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the question and the answers.
 
Mahmoud Hossam
Ranch Hand
Posts: 74
Netbeans IDE Tomcat Server Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the question gives you this code and asks about the result

Answers :

A. Compilation succeeds
B. Compilation fails due to an error on line 8
C. Compilation fails due to an error on line 10
D. Compilation fails due to an error on line 12
E. Compilation fails due to an error on line 14

-Choose all that apply
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what are you considering this?
the CC5 class doStuff() method does not declare any new or broader checked exceptions and it compiles fine
so the answer is only C
because we cannot declare any new checked exceptions or broader exceptions for the overriding method
happy learning
 
Mahmoud Hossam
Ranch Hand
Posts: 74
Netbeans IDE Tomcat Server Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:what are you considering this?
the CC5 class doStuff() method does not declare any new or broader checked exceptions and it compiles fine
so the answer is only C
because we cannot declare any new checked exceptions or broader exceptions for the overriding method
happy learning



shouldn't it declare throwing SubException?
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
of course there is not need to declare that it throws subException
Remember
when overriding the method you can either declare fewer exceptions, no exceptions or narrower exceptions
for demonstrating my point
here is the sample program
that compiles fine


hope this helps
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
prasd is corect
 
Mahmoud Hossam
Ranch Hand
Posts: 74
Netbeans IDE Tomcat Server Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Prasad,I now know the correct answer
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic