Create a Java program to demonstrate method overloading with overloaded methods that use different types of arrays as parameters
class Calculator { int sumArray(int[] numbers) { int sum = 0; for (int num : numbers) { sum += num; } return sum; } int sumArray(Integer[] numbers) { int sum = 0; for (Integer num : numbers) { sum += num; } return sum; } } public class Main { public static void main(String[] args) { Calculator calculator = new Calculator(); int[] arr1 = {1, 2, 3, 4, 5}; Integer[] arr2 = {2, 4, 6, 8, 10}; System.out.println("Sum of Int Array : " + calculator.sumArray(arr1)); System.out.println("Sum of Integer Array : " + calculator.sumArray(arr2)); } }
Sum of Int Array : 15 Sum of Integer Array : 30
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions