Skip to content

Instantly share code, notes, and snippets.

@rajeevprasanna
Created January 19, 2014 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeevprasanna/8501298 to your computer and use it in GitHub Desktop.
Save rajeevprasanna/8501298 to your computer and use it in GitHub Desktop.
Overloading return type
package legalReturnTypes.overloadedMethods;
public class Bar extends Foo {
String go(int x) {
return null;
}
// Bar version of the method uses a different return type. That's perfectly
// fine. As long as you've changed the argument list, you're overloading the
// method, so the return type doesn't have to match that of the superclass
// version.
/*
* String go() { // Not legal! Can't change only the return type return
* null;
* }
*/
}
package legalReturnTypes.overloadedMethods;
public class Foo {
void go() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment