Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Nirbhay Agarwal
2,852 PointsJAVA Objects
so you cannot declare two methods with the same signature even if they have a different return type.
Why so the return type is different suppose you want same signature for another method in the code. what you will do ?
different return type but same signature
like that if you create a signature it will be used only once in the whole program
2 Answers
Zachary Kaufman
1,463 PointsWhat do you mean by "signature"...? You can do this
public void hotDogs() {
}
public void hotDogs(String toppings) {
}
or even
public boolean hotDog(String toppings, int amount) {
}
but I don't think you can do
public void hotDogs() {
}
public boolean hotDogs() {
}
Does this help?
codebyamir
12,108 PointsThe Java language does not allow two methods with same name to have identical parameters and different return types.
It will result in a compile-time error.
http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2