Create a Java program to demonstrate method overloading with primitive data types and their wrapper classes
This Java program demonstrates method overloading with primitives and their corresponding wrapper classes in a class named MethodOverloadingDemo.
public class OverloadingWithPrimitivesAndWrappersDemo { public static void main(String[] args) { MethodOverloadingDemo calculator = new MethodOverloadingDemo(); int intSum = calculator.add(5, 10); Integer integerSum = calculator.add(15, 20); double doubleSum = calculator.add(3.5, 4.5); Double doubleObjSum = calculator.add(7.5, 8.5); System.out.println("Sum of int : " + intSum); System.out.println("Sum of Integer : " + integerSum); System.out.println("Sum of double : " + doubleSum); System.out.println("Sum of Double : " + doubleObjSum); } } class MethodOverloadingDemo { int add(int a, int b)// Method to add two integers { return a + b; } Integer add(Integer a, Integer b)// Method to add two Integer objects { return a + b; } double add(double a, double b)// Method to add two doubles { return a + b; } Double add(Double a, Double b)// Method to add two Double objects { return a + b; } }
Sum of int : 15 Sum of Integer : 35 Sum of double : 8.0 Sum of Double : 16.0
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions