T
Thomas Hawtin
sarathy said:I have doubt in the signature of the main method.
Why public?
Any how only JVM is going to invoke it. No one is going to
call main from other classes/packages. Then a private will do for this.
A method to call when starting a program seems like it should be very
public to me. The only really odd thing is that the class does not need
to be public.
Why static?
Why was the main method restricted from accessing
non-static instance variables/methods.
Which object would you expect it to be called upon?
Why void?
Normally any main method MUST return a value so that it's
exit value is can be used by other programs. Why is it void here?
Certainly in C++ the return can be elided. That's a special case in that
language. For my money, that doesn't buy its way, but it falls out of
growing up from K&R C.
Java programs are multithreaded. Usually the main method exits almost
immediately. It rather makes sense for the exit code to be specified
when an exit is requested (through System.exit).
Tom Hawtin