• 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 assertion

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this question in one of the mock exams on assertions is says that the methodA int the class Asserttest throws Assertion error which of the following method can be legally placed in the subclass of the Asserttest

code:
public class Asserttest{
public void methodA(int i) throws AssertionError
{
assert i<1024:"Invalid value";
}
}

The options are:
1. public void methodA(int i)
2. public void methodA(int i) throws Exception
3. public void methodA(int i) throws Throwable
4. public void methodA(int i) throws Error
5. only A is the valid option

i answered as 1,5 but the answer is 1,4 how is option 4 right please explain...
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi preetha vasudevan,

When we take overriding rules in to consideration, the rules are applied to checked exceptions only only only. ok.
Error is unchecked exception. That's why it not considerable.


If you override a method from a super class the checked exceptions that the subclass method declares cannot be more general than those of the superclass method. ( It is Ok to throw more specific exceptions, or not to throw any exceptions in the subclass method). In particular, if the super class method throws no checked exception at all, neither can the subclass.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Preetha,
The Overriding Method can throw Exceptions that is a superclass of the exceptions thrown in the overridden method.

Since
class AssertionError extends Error ()

Option 4 is right I guess..
 
Cheenu Subramanian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Extremely Sorry ..
Posted an incorrect and wrong reply
 
Cheenu Subramanian
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Extremely Sorry ..
Posted an incorrect and wrong reply
 
Preetha Vasudevan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you krishna
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic