Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Muaz Bashara   on Oct 07 In Java Category.

  
Question Answered By: Farah Khan   on Oct 07

I don't know about this, but you seem to have been
able to both run and compile, at least you say so,
without having the right declarations for the main()
method.

The reason why the main() method should be public, is
so that you can access it, that is starting the
application. It can't be instantiated either, so
therefore it's static. An application should not
return anything, therefore it's void.

Now, if you made this hack work, it's probably
beacause you're compiling/running it with an earlier
version of Java, I don't know how early it has to be
though, but it may work with 1.1. In C++ for example
you have the main() method declared as int and you
don't write public static  and the rest, but I read (I
believe in Java Language Specification from Sun) that
when they "revamped" C++ into Java, which is how Java
is explained as being in the earliest Java books, they
corrected these errors. So, don't worry about how the
hack might work, the same "error" works  in C++ all the
time.

I want to thank the Java creators for crating a much
more perfect language as java has a lot more elegant
debugger than its' predecessor and the just for Java
invented garbage collector.

Happy programming and I really recommend the
downloadable book I mentioned above.

Share: 

 

This Question has 9 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on private static void main Or get search suggestion and latest updates.


Tagged: