0% found this document useful (0 votes)
16 views3 pages

Method Overloading in Java

Uploaded by

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

Method Overloading in Java

Uploaded by

tmslevents2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

class CalculateSquare

{
public void square()
{
System.out.println("No Parameter Method Called");
}
public int square( int number )
{
int square = number * number;
System.out.println("Method with Integer Argument Called:"+square);
}
public float square( float number )
{
float square = number * number;
System.out.println("Method with float Argument Called:"+square);
}
public static void main(String[] args)
{
CalculateSquare obj = new CalculateSquare();
obj.square();
obj.square(5);
obj.square(2.5);
}
}

class Demo
{
void multiply(int a, int b)
{
System.out.printIn("Result is"+(a*b)) ;
}
void multiply(int a, int b,int c)
{
System.out.printIn("Result is"+(a*b*c));
}
public static void main(String[] args)
{
Demo obj = new Demo();
obj.multiply(8,5);
obj.multiply(4,6,2);
}
}

class Sum
{
static int add(int a, int b)
{
return a+b;
}
static double add(double a, double b)
{
return a+b;
}
}
class TestOverloading2
{
public static void main(String[] args)
{
System.out.println(Sum.add(17,13));
System.out.println(Sum.add(10.4,10.6));
}
}
class Sample{
int disp(int x){
return x;
}
double disp(int y){
return y;
}
public static void main(String args[])
{
Sample s = new Sample();
System.out.printIn("Value of x : " + s.disp(5));
System.out.printIn("Value of y : " + s.disp(6.5));
}
}

// Java program to demonstrate working of method


// overloading in Java

public class Sum {


// Overloaded sum(). This sum takes two int parameters
public int sum(int x, int y) { return (x + y); }

// Overloaded sum(). This sum takes three int parameters


public int sum(int x, int y, int z)
{
return (x + y + z);
}

// Overloaded sum(). This sum takes two double


// parameters
public double sum(double x, double y)
{
return (x + y);
}

// Driver code
public static void main(String args[])
{
Sum s = new Sum();
System.out.println(s.sum(10, 20));
System.out.println(s.sum(10, 20, 30));
System.out.println(s.sum(10.5, 20.5));
}
}

class Product {
// Multiplying three integer values
public int Prod(int a, int b, int c)
{
int prod1 = a * b * c;
return prod1;
}

// Multiplying three double values.


public double Prod(double a, double b, double c)
{
double prod2 = a * b * c;
return prod2;
}
}

class GFG {
public static void main(String[] args)
{
Product obj = new Product();

int prod1 = obj.Prod(1, 2, 3);


System.out.println(
"Product of the three integer value :" + prod1);

double prod2 = obj.Prod(1.0, 2.0, 3.0);


System.out.println(
"Product of the three double value :" + prod2);
}
}

You might also like