Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returning int from the main....

 
abhishek kunal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cant we return int from main function of a class...so the main method's signature w'd look like public static int main(String args[]), i ahve done it, but it shows a problem, NoSuchMethodError . isn't there any way to overcome this limitation???
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what do you expect the application to do with the int that is returned?

If you are expecting it to return as the exit code, as in a C application, then you can accomplish the same thing with using the system exit() method. The parameter passed to the exit method is the exit code.

Henry
 
Praveen Sangolli
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JVM is the one that calls the main method and what will the JVM do with the int that you return. No you cannot change the method signature for public static void main(String args[])
 
abhishek kunal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm, so main method doesn't provide this, we have to achieve this by System.exit(), while it was possible by both ways in c++......anyways tx!!
 
abhishek kunal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gud!! tx !!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abhishek kunal wrote:... while it was possible by both ways in c++......

Yes, but Java is not C++, there's no reason why it should be the same in Java as it is in C++.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abhishek kunal wrote:gud!! tx !!
Please don't write gud, tx, or similar.
 
abhishek kunal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh i am very sorry, it was polite and humble from my side...please don't take it other way...
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies accepted. I knew what you meant, but other people who didn't grow up speaking English might not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic