Create a Java program to demonstrate method overloading with overloaded methods that use different parameter types and return types, including type casting
class Calculator { int add(int a, int b) { return a + b; } double add(double a, double b) { return (double) (a + b); } } public class Main { public static void main(String[] args) { Calculator calculator = new Calculator(); System.out.println("Sum of Two Integers : " + calculator.add(5, 3)); System.out.println("Sum of Two Doubles (with Casting) : " + calculator.add(3.5, 2.7)); } }
Sum of Two Integers : 8 Sum of Two Doubles (with Casting) : 6.2
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions