answersLogoWhite

0

Below is an example of method overloading which returns the sum of two number types. Each method performs the calculation and returns a value in a different type.

int sum(final int a, final int b) {

return a + b;

}

long sum(final long a, final long b) {

return a + b;

}

float sum(final float a, final float b) {

return a + b;

}

double sum(final double a, final double b) {

return a + b;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

Operator overloading is possible in java or not?

Java does not support opperator overloading, so the answer to your question is: none.


Can we execute java program without main function?

no


In java public static voidmain function denotes what?

Java's main function denotes the entry point into the execution of your program.


What is the function of this in java?

this in java is a keyword that refers to the current object of the class. It is also used in constructor overloading when you want to invoke one constructor from another within the same class.


What is the name of the function which must be defined in a Java program?

The main function. Every program must have a main function and it must be declared static.


What is function overloading in java?

Any function or method in Java that is coded by the programmer is called a user defined method in Java. The JAVA API (Application Programming Interface) has a set of predefined classes & methods that are for our usage. Whatever methods we create apart from these are termed as user defined methods. In java we not use the term functions. We call them "Methods"


How do you write a java menu driven program using function overloading?

To create a menu-driven program in Java using function overloading, define multiple methods with the same name but different parameters to perform various tasks. For example, you could create overloaded calculate methods that accept different data types (e.g., int, double) for performing calculations. In the main method, present a menu to the user, take their choice as input, and call the appropriate overloaded method based on their selection. This allows for a clean and organized way to handle multiple functionalities with similar operations.


What is main advantage of using constructors in java?

Constructors have the same name as the class itself and they do not specify a return type, not even void because they return the instance of the class itself. Because constructors have the same name as the class then they allow method overloading and also save memory and execution time of program. Program release memory of constructors function after using this function and it reduce program complexity.


Why java not support oprator overloading?

Pressumably, the designers of Java thought this would lead to confusing code.


Write java program for addition of two objects?

May be link might help -> http://www.allinterview.com/viewpost/408298.html There it is implemented through...... Operator Overloading!


Rules for function overloading?

It's a way by which you use define the same function for different input types. For example, think about the the operator "+" which in java works for adding integers, floating point numbers and even string concatenation. The way such functionality is achieved is by overloading.


How many constructor can be defined in a classin java p rogramming?

how many constructer can be defined in class in overloading of java programming