• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why main() function does not return any value

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All

there are some questions that I know it will happen but don't
know the reason WHY?

1> Why can't main function return any value .

for eg:

<CODE>

class try1
{
public static int main(String agrs[])
{
System.out.println("Hello" );
return 0 ;

}
}

</CODE>

though it compiles ok but gives run time Error.


2> System.out.println("Hello" );

where System is a class
out is an object of static PrintStream ?
println is a method

is it possible for a static PrintStream to have an OBJECT?

or I am missing something?




Thank You


Anshul Mathur
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1> Why can't main function return any value .



The answer is "just because that's how they designed it." What fascinates me is that exit() takes an int status code, while main returns void; clearly a mistake on somebody's part.

Is it possible for a static PrintStream to have an OBJECT?



"out" is a static variable (or "class" variable) of the System class.
 
Anshul Mathur
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks A lot.
 
Don't MAKE me come back there with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic