Example of Method overloading with type promotion

Example of Method overloading with type promotion.
class Area
{
void Calculate(long l,long b)
{
System.out.println(“Area is”+(l*b));
}
void Calculate(int l, int b,int h)
{
System.out.println(“Area is”+(l*b*h));
}
public static void main (String[] args)
{
Area a = new Area();
a.Calculate(5,4); //automatic type conversion from find(int,int) to find(long,long) .
a.Calculate(2,4,6)
}
}

Output :
Area is 20
Area is 48

Leave a Reply

Your email address will not be published. Required fields are marked *