Java Program to Implement Method Overloading Based on Type Promotion

You are currently viewing Java Program to Implement Method Overloading Based on Type Promotion

Java program to implement method overloading based on type promotion

// Java program to implement method overloading 
// based on type promotion

public class Main {
  static double sum(int num1, int num2) {
    double s = 0;
    s = num1 + num2;
    return s;
  }
  
  static double sum(int num1, double num2) {
    double s = 0;
    s = num1 + num2;
    return s;
  }

  public static void main(String[] args) {
    double result = 0;

    result = sum(10, 20);
    System.out.println("Sum : " + result);

    result = sum(20, 20.56F);
    System.out.println("Sum : " + result);
  }
}

Output

Sum : 30.0
Sum : 40.55999946594238

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply