Overloading
Code 1:
public class Foo {
public void doStuff(int y, String s) { }
public void moreThings(int x) { }
}
class Bar extends Foo {
public void doStuff(int y, long s) throws IOException { }
}
In the above code i know the dostuff method is over loaded
but if i make the following changes in code :
Code2:
public class Foo {
public void doStuff(int y, String s) { }
public void moreThings(int x) { }
}
class Bar extends Foo {
public void doStuff(int y) throws IOException { } //Here the arguments is same as the base class
}
Question1:- Adding an exception to method brings in a difference to make a method overloaded. And how does it makes a difference in second code for overriding?
Question2:- Difference between checked and unchecked Exceptions?
> public class Foo {
>public void doStuff(int y, String s) { }
> public void moreThings(int x) { }
> }
> class Bar extends Foo {
> public void doStuff(int y) throws IOException { } //Here the arguments is same as the base class
Those aren't the same arguments. If they were, it would override rather than overload the method.
> Question1:- Adding an exception to method brings in a
> difference to make a method overloaded. And how does
> it makes a difference in second code for overriding?
I don't understand your question, but I'll make a guess at what I think you're asking. If you're overriding a method, you can't throw a more general Exception than the overridden method. This makes sense because existing code that catches the more "narrow" exception would need to be rewritten.
> Question2:- Difference between checked and unchecked Exceptions?
[url=http://java.sun.com/docs/books/tutorial/essential/exceptions/]The Java?Tutorial - Lesson: Handling Errors with Exceptions[/url]
~