Hello world !
In this post we are going to know about overloading.
When several functions are specified for a single function name in the same scope,the function name is said to be overloaded.
Java has achieved Oops concept " polymorphic" by implementing "overloading" concept
In this post we are going to know about overloading.
When several functions are specified for a single function name in the same scope,the function name is said to be overloaded.
Java has achieved Oops concept " polymorphic" by implementing "overloading" concept
"Same name different work"
Java allows function to have the same name ,distinguish by them by their :
1. their number of arguments
or
2.Type of arguments .
for example:
class Number
{
static float divide (int a , int b)
{
.....
.....
}
static float divide (float x, float y)
{
....
....
}
}
That is ,divide () function taking two int arguments is different from divide() taking two float arguments.
This is known as function overloading
def: " A function name having several definitions in same scope that are differential by the number or types of their arguments,is said to be an overloaded function"
Now these methods( functions) can be used as follows:
for dividing integer
Number.divide(8,2)
for dividing real (floating) number
Number.divide(8.4,2.3)
Comments
Post a Comment