Create a Java program to demonstrate method overloading with overloaded methods that use different combinations of parameter modifiers, including final and varargs
public class OverloadingWithParameterModifiersAndVarargsDemo { public static void main(String[] args) { MethodOverloadingDemo printer = new MethodOverloadingDemo(); String message = "Hello World"; int number = 67; printer.printInfo(message, 1, 2, 3, 4, 5); printer.printInfo(number, "How", "are", "you?"); } } class MethodOverloadingDemo { void printInfo(String message, int... numbers) // Method with a non-final parameter and varargs { System.out.println("Printing non-final with varargs : " + message); for (int num : numbers) { System.out.print(num + " "); } System.out.println(); } void printInfo(final int number, String... messages) // Method with a final parameter and varargs { System.out.println("Printing final with varargs : " + number); for (String msg : messages) { System.out.print(msg + " "); } System.out.println(); } }
Printing non-final with varargs : Hello World 1 2 3 4 5 Printing final with varargs : 67 How are you?
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions