Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

January 18, 2010

All about Overloading

The rules are simple:

Overloaded methods MUST change the argument list.

Overloaded methods CAN change the return type.

Overloaded methods CAN change the access modifier.

Overloaded methods CAN declare new or broader checked exceptions.

A method can be overloaded in the same class or in a subclass. In other words, if class A defines a dostuff(int i) method, the subclass B could define a dostuff (String s) method without overriding the superclass version that takes an int. So two methods with the same name but in different classes can still be considered overloaded, if the subclass inherits one version of the method and then declares another overloaded version in its class definition.

No comments: