Method
Overloading:
We can have more than one method with the same name as long as
they differ either in number of parameters or type of parameters. This is
called method overloading. The difference in the method call is made on the
basis of,
* Number of
arguments
* Type of
arguments
* Sequence of
arguments
class Overload
{
void area(int
side)
{
int
ar;
ar=side*side;
System.out.println("Area
of Square :"+ar);
}
void area(double
radius)
{
double
ar;
ar=3.14*radius*radius;
System.out.println("Area
of Circle :"+ar);
}
void area(int
length,int width)
{
int
ar;
ar=length*width;
System.out.println("Area
of Rectangle:"+ar);
}
}
class OverDemo
{
public static
void main(String args[ ])
{
Overload
ob=new Overload( );
ob.area(5);
ob.area(8,9);
ob.area(6.7);
}
}
Comments
Post a Comment