Oh I see what you are getting at.
Sanjana Sharma wrote:
Now I see an example where the superclass method declares a checked exception in the method but the sub class method( overriding method) doesn't.
This is perfectly legal, because throwing less exceptions doesn't mean that a subclass isn't IS-A super class. Maybe the subclass has error handling so doesn't need to throw that exception.
Sanjana Sharma wrote:
Now if the superclass reference is to refer the subtype object with the overriding method, I see a compiler error - unreported exception. Why is this..? Is it because the complier just checks for the "presence " of the method in the super class..?
Basically, there is a reason that you are using the super class reference right? Maybe you need to call code that doesn't know about the subclass. Regardless, it has to behave like the superclass. So, the compiler treats it as such..... Or you can say the compiler isn't smart enough.
Henry