• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception thrown by sub class  RSS feed

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If submain() is overridden and it does not throw any exception, is that allowed ? (Overriding rule says, exception thrown by subclass method can be of narrower class than super method. Does not throwing any exception by ub class method qualify as narrower class exception ?)
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is allowed. Not throwing an exception at all is considered narrower.
 
Rajat Jindal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Line18 i.e "//4" will give you compile time error:



Important point is that whenever you will call the method polymorphically than you will need to either throws the exception or will need to write it in try-catch block.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!