Write a Java program to demonstrate method overloading with different parameter types and their subclasses
public class OverloadingWithSubclassesDemo { public static void main(String[] args) { MethodOverloadingDemo printer = new MethodOverloadingDemo(); String str = "Hello World!"; Integer integer = 23; Double dbl = 84.14; printer.printInfo(str); // Calls the method for String printer.printInfo(integer); // Calls the method for Number printer.printInfo(dbl); // Calls the method for Number (Double is a subclass of Number) } } class MethodOverloadingDemo { void printInfo(String message) { System.out.println("Printing String : " + message); } void printInfo(Number number) { System.out.println("Printing Number : " + number); } }
Printing String : Hello World! Printing Number : 23 Printing Number : 84.14
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions