Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does return value of main function need to be an integer

Status
Not open for further replies.

shadowlesshand

Programmer
May 29, 2002
21
HK
Hi All,

I would like to know if the return value of the main function in java (or any other language) actually needs to be an integer.

Also what would the integer value be.

If I use void as my return type, does it nullify the integer value it is actually returning?


Thanks a million,
Karthik
 
The main function for java:
public static void main(String[] args){}

As you can see, the return type is void, thus no value is returned. If you give it a return type other than void, you will get an exception stating that the main function does not exist.

Also if working with constructors, the return type would be void as a constructor is normally only used to initialize the private variables and other objects needed for the class to function. Constructors return objects of the class they represent, so you would have to declare a variable of that class or the object class when calling a constructor.

Thus all your 'main' functions usually do not return a value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top