java - Why is it that an overridden method can't throw a new checked Exception -


i have 2 questions :

  1. what purpose of constraint overridden method can't throw new checked exception?
  2. why allowed overridden method can throw or none, or subset of checked exceptions specified in throws clause of overridden method in superclass?

in both cases, it's because base method you're overriding has set contract calling code; if add checked exceptions method may throw, you'd breaking contract.

consider class base method foo throws checked exception someexception. have derived derives base , overrides foo. code in app using base b variable initializing new instance of derived, , calling b.foo(). contract foo throws someexception; throwing else breaks contract.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -