File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question on assertion

 
Preetha Vasudevan
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • 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...
 
Krishna Latha Grandhi
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Cheenu Subramanian
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extremely Sorry ..
Posted an incorrect and wrong reply
 
Cheenu Subramanian
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extremely Sorry ..
Posted an incorrect and wrong reply
 
Preetha Vasudevan
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you krishna
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic