answersLogoWhite

0


Best Answer

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

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

Just write two methods with the same name, but different types of parameters.

Just write two methods with the same name, but different types of parameters.

Just write two methods with the same name, but different types of parameters.

Just write two methods with the same name, but different types of parameters.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Just write two methods with the same name, but different types of parameters.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program in Java to illustrate the function overloading?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Operator overloading is possible in java or not?

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


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.


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 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"


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 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 operator overloading differ from function overloading?

Function overloading is multiple definition with different signatures(the parameters should be different) for the same function. The parameter list have to be different in each definition. The compiler will not accept if the return type alone is changed. Operator overloading is defining a function for a particular operator. The operator loading function can not be overloaded through function 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