This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Abstract class in hierarchy

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
In the Exam Cram for Java 2 book, there is a sample test question phrased like this (on pg 313):


You are writing a set of classes related to cooking and have created your own exceptino hierarchy derived from java.lang.Exception as follows:
BadTasteException
+----BitterException
+----SourException
BadTasteException (a subclass of Exception) is defined as an abstract class.
You have a method eatMe that may throw a BitterException or a SourException. Which of the following method declarations will be acceptable to the compiler? [check all correct answers]
a. public void eatMe(Ingredient[] list) throws BadTasteException
b. public void eatMe(Ingredient[] list) throws BitterException, SourException
c. public void eatMe(Ingredient[] list) may throw BadTasteException
d. public void eatMe(Ingredient[] list)


The answers: a, b. I agree with b. But why a? How can an abstract class know what to do with an exception?
Any insight would be appreciated. Thanks,
--kkoszegi
[ January 29, 2002: Message edited by: Kelley Koszegi ]
[ January 29, 2002: Message edited by: Kelley Koszegi ]
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BitterException is a BadTasteException
u can use any supertype.which can be assaignable
to it,u can assaign
BadTasteException e=new BitterException();
so u can use it.no problom with abstract
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic