Friday 17 June 2011

Java Overloading

Overloading is the same method name with different parameters.
the Constructors can be overloaded
**Methods with Same name in The Class or its Subclasses with different Signature.
Signature (Parameters DataTypes or Number)ex
Class A{
public A(){....}
public A(int x){....}
public A(char x){....}
public void getSomeThing(){.....}
public void getSomeThing(char x){.....}
public void getSomeThing(String x,int y){.....}
public void getSomeThing(double x){.....}
}
Class B extends A{
public void getSomeThing(String x,char y){.....}
}
** You can pass float or double to method who's parameter datatype is double but contrary is prohibited


The overloaded methods can be static , final and or abstract.


Hint: Java uses method Parameters Types and count to specify which method.
Java doesn't differentiate between methods depending on there return DataType 


Hint: Use Overloading when you need multiple methods with different parameters, but methods do the same thing.
Don't use Overloading when methods do different tasks


For more info: http://www.java-samples.com/showtutorial.php?tutorialid=284


No comments:

Post a Comment