Methods Overloading

Overloading in java means that two or more methods in same class, having same name can operate by having different input parameters.

If the class is overloaded, then compiler uses the best method as per the parameters delared and gives result.

Overloading is useful when there are multiple cases of computation when certain input variables are unknown



package classes_methodOverlaoding;

public class myClass {
	public static void main(String[] args){
		class_next mclass=new class_next();
		System.out.println("No Input = "+mclass.numericals());
		System.out.println("Single Input "+ mclass.numericals(55));
		System.out.println("Double Input "+ mclass.numericals(55,65));		

package classes_methodOverlaoding;

public class class_next {

	public int numericals() {
		return 20;
	public int numericals(int i) {
		return i;
	public int numericals(int i,int j) {
		return i+j;

output :
No Input = 20
Single Input 55
Double Input 120

Related Tutorials