0% found this document useful (0 votes)
6 views1 page

Java Method Overloading Example

The document is a Java program that demonstrates method overloading with three different 'fun' methods. The first method prints a sequence of numbers, the second prints a rectangle of asterisks, and the third returns the smaller of two double values as an integer. The main method interacts with the user to gather input for each of these methods and displays the results.

Uploaded by

testvk525
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Java Method Overloading Example

The document is a Java program that demonstrates method overloading with three different 'fun' methods. The first method prints a sequence of numbers, the second prints a rectangle of asterisks, and the third returns the smaller of two double values as an integer. The main method interacts with the user to gather input for each of these methods and displays the results.

Uploaded by

testvk525
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import [Link].

*;
class Overload
{
void fun(int n)
{
int a = 2, diff = 3;
for(int i = 1; i <= n; i++)
{
[Link](a + " ");
a = a + diff;
diff = diff + 2;
}
[Link]();
}

void fun(int x, int y)


{
for(int i = 1; i <= x; i++)
{
for(int j = 1; j <= y; j++)
{
[Link]("*");
}
[Link]();
}
}

int fun(double a, double b)


{
if(a < b)
return (int)a;
else
return (int)b;
}

public static void main()


{
Scanner sc = new Scanner([Link]);
Overload ob = new Overload();
[Link]("Enter number of terms:");
int n = [Link]();
[Link](n);
[Link]("Enter x and y:");
int x = [Link]();
int y = [Link]();
[Link](x, y);
[Link]("Enter two numbers:");
double a = [Link]();
double b = [Link]();
[Link]("Smaller number is: " + [Link](a, b));
}
}

You might also like