r/javahelp • NYU '18 • Sep 21 '16

does this code compile? why or why not?

class Hello{
    public static void main(String[] args){}
    private int main(String[] myArray){}
    }

**Does it have something to do with having the same constructor name?

1 Upvotes

7 comments sorted by

10

u/desrtfx Out of Coffee error - System halted Sep 21 '16 edited Sep 21 '16

Honestly, the best way to answer this question is to actually try it yourself rather than asking.

Grab an editor, write the code, compile it and test it.

Practice is the best way to learn.

Edit: To whoever downvoted: You might not like this reply, but it is one very sensible one. The time it took OP to write the post could have been way better utilized typing & compiling the code and getting an immediate answer.

Practice beats theory. Doing beats asking. You might not like this, but it is a proven fact.

1

u/Kusoyaro0o NYU '18 Sep 22 '16

Thanks

7

u/[deleted] Sep 21 '16

No. Int typed function has no return for one thing

2

u/lady-linux Sep 21 '16

Well, does it compile?

1

u/OffbeatDrizzle Sep 21 '16

We don't do homework...

1

u/nutrecht Lead Software Engineer / EU / 20+ YXP Sep 21 '16

Those aren't constructors but methods. And yeah, you can't have two methods with the same name and arguments no matter their return type (void/int) or accessibility (public/private).