• Post Reply Bookmark Topic Watch Topic
  • New Topic

working with inheritance and exception  RSS feed

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ranchers....can some one explain me rules to define exception in base class as well as super class constructors...i have cleared my concept with respect to over riding methods and exception, but finding it difficult to work with constructors...






}...

but if i do

..

.trickier part comes when



can anyone please give me justification on above behaviour..
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you have an exception thrown from a constructor, you need to thrown or handle at least that exception. Constructors can't be "overridden", you call super() to call the superclass's constructor. Notice the error is on the line with super(). If you don't do this, then an error may be thrown in super() that is neither caught nor handled. This is illegal.

Overriding a method, on the other hand, is saying, "Run me instead of the super's method." The subclasses this has to fulfil the super's "obligations", so it can catch or throw IOException or a subclass. This is because someone using the superclass must catch or throw IOException and FileNotFound is a subclass of that.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!