Method overloading, also known as function overloading, is the ability of a class to have multiple methods with the same name, granted that they differ in either number or type of arguments. Compiler checks method signature for method overloading.
Method signature consists of three things :
The program demonstrates the concept of method overloading in Java.
//Method Overloading in Java class MathOperation { public static int multiply(int a, int b) { return a * b; } public static double multiply(double x, double y) { return x * y; } public static double multiply(double i, int j) { return i * j; } public static int multiply(int r) { return r*r; } } public class methodOverloading { public static void main(String arg[]) { System.out.println("Multiply 2 Integer Value : " + MathOperation.multiply(25, 10)); System.out.println("Multiply 2 Double Value : " + MathOperation.multiply(2.5, 8.5)); System.out.println("Multiply Double & Integer Value : " + MathOperation.multiply(2.5, 8)); System.out.println("Multiply Integer Value : " + MathOperation.multiply(2)); } }
Multiply 2 Integer Value : 250 Multiply 2 Double Value : 21.25 Multiply Double & Integer Value : 20.0 Multiply Integer Value : 4To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions