int calculateSum(int i,int j)
float calculateSum(float i,int j)
double calculateSum(double i,int j)
float calculateSum(int i,float j)
World of tricky Core Java Q&A(Java SE),Java EE and Open source technologies like Struts,Hibernate,Spring,Velocity etc
Disclaimer
Interview Questions On Java,Java EE Copyright © 2012
4 comments:
http://stackoverflow.com/questions/1696314/java-different-return-types-when-overloading
Check this link. The examples that you have given here are bad. You can not change the method return types (unless the return type follows inheritance itself) while overloading. Overloading means changing the parameter types or number of parameters. If you can recall, checked exceptions in the throws clause of the methods follow the hierarchy in overriding.
It is still debated as per the post...thx for your comments Anoop.
Hi,
I tried int calculatesum()
and string calculatesum(), the compiler complains, calculatesum is already declared but when I try
int calculatesum(int i, float j) and int calculateSum(int i,int j) it works, so I am not sure how overloading really works.
You can still change a method return type as long as the method signature is/are different.Overloaded methods are differentiated by the number and the type of the arguments passed into the method. http://download.oracle.com/javase/tutorial/java/javaOO/methods.html
Post a Comment