As we know that a method have its own signature which is known by method's name and the parameter types.
Method Overloading
As we know that a method have its own signature which
is known by method's name and the parameter types. Java has a powerful feature
which is known as method overloading. With the help of this feature we can
define two methods of same name with different parameters. It allows the
facility to define that how we perform the same action on different type of
parameter.
Here is an example of the method overloading. Create a class "mol" and
subclass "Test". Now we create two methods of same name
"square" but the parameter are different. When the main class call the
method the method executes on behalf of the parameter. In the given example we
are trying to illustrate the same technique.
Here is the Code of the Example :
"mol.java"
import java.lang.*;
|
Here is the Output of the Example :
C:\roseindia>javac mol.java C:\roseindia>java mol 49 129.96 |