Can methods be overloaded based on the return types

Showing Answers 1 - 15 of 15 Answers

srinivasa reddy

  • Jul 27th, 2005
 

No,we cant overload methods based on the return types

  Was this answer useful?  Yes

M.Manikumar

  • Aug 13th, 2005
 

A method cannot be overloaded on the bases of return types because the compiler will check only the name of the method and the arguments.So a method cannot be overloaded on the bases of return types.

  Was this answer useful?  Yes

Archana

  • Sep 15th, 2005
 

The method can be overloaded only on the following basis :

1. The method name are same (including the case . viz. addname and addName are not the same)

2. The signatures(argument)  of the method .

return type can not be used for the method overloading.

radheycet

  • Aug 29th, 2008
 

Yes method can be overloaded on the basis of return type.
consider the following example



public class method {

void add(int a, int b)
{System.

out.println("the value after addition is=" + (a + b));

}

 

double add(double c, double d)//overloaded based on return type.
 {
return (c + d);

}

 

public static void main(String args[]) {method ob1 = new method();

ob1.add(2, 3);

System.out.println("the value after addition is=" + ob1.add(10.0, 12.0));

}

 

}

  Was this answer useful?  Yes

ya, methods can be overloaded based on the return type. You might be confused this with the Overriding.

In method Overriding, it is not possible to change the return type, the entire prototype has to be the same as the of overridden method.

While Overloading methods we can change the 1)return type, 2)Parameter types 3) No of Parameters, 4) Order of parameters.

  Was this answer useful?  Yes

dheerendra

  • Sep 2nd, 2008
 

Methods cannot be overloaded only on the basis of return type atleast one argument should be different, otherwise compiler will give the message "The function is already defined in the class".

  Was this answer useful?  Yes

Anonymous

  • Mar 3rd, 2016
 

We can call the method by their name and not by their type;;
Method::
int sum()
void sum()
calling::
Where object is a;
a.sum();
here, it will arise ambiguity which method to call, void sum() or int sum() and thus compiler give error

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions