This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
The main that you have defined is not a PSVM.... it is a method which belongs to class Sample.
What do you mean by PSVM ?
The above method is also public , static , returns nothing ( void ) and it's name is 'main' !! Can't it be called as PSVM ? [ August 28, 2006: Message edited by: Srinivasa Raghavan ]
The main that you have defined is not a PSVM.... it is a method which belongs to class Sample.
Dear Devesh,
what is the difference between
in concern of Class. Both are simple methods belongs to class sample.
Am I wrong??
And By pointing out the errors in the questions-answers. I am not intended to be critical, But I just want to correct the errors so that Other who may visit the site may not be misguided.
That's why I only pointed out the errors. Please don't be get hurted
My guess on what the person may have meant by asking
"Q: Can I have multiple main methods in the same class?"
is
PSVM is the short form for public static void main method which is always looked up by the JVM for the starting point to a program
when we run java someclass, jvm will search for a public static void main (String[] anyparam){} inside someclass as the starting point.
the difference between
public static void main (String[] anyparam){} and public static void main (int[] anyparam){}
is the int param method is not something the jvm going to reference when the class needs to be run.
so when we say, we cannot have overloaded main's, it means the JVM will not recognise any method other than "public static void main (String[] anyparam){}" as the start for the program.
But I do agree the question is a bit misleading, it can be rephrased to convey what the intention is? As I am not the author, I can just try to understand what may have been meant ...... [ August 28, 2006: Message edited by: Devesh H Rao ]
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
posted
0
PSVM is the short form for public static void main method which is always looked up by the JVM for the starting point to a program
I do agree that PSVM is public static void main but not public static void main with String args.
So going to the main discussion Can I have multiple main methods in the same class Yes can have, because it also a normal method & can be overriden with different args.
For your answer the question should be like this Can JVM invoke a main method with an argument other than String[] ? A big No !
I do agree that PSVM is public static void main but not public static void main with String args.
So going to the main discussion Can I have multiple main methods in the same class Yes can have, because it also a normal method & can be overriden with different args.
For your answer the question should be like this Can JVM invoke a main method with an argument other than String[] ? A big No !
I do not know when you started coding, but if you have ever worked on JDK 1.3 in some versions of JVM
private static void main(String[] args){} worked.
I have personally tried that when I started out coding and I remember, I had a query on the same in Javaranch itself on how it could possibly work.
How can a private method belonging to a class be called by the JVM, or does the PSVM belong to the class it is declared to in the first place...?
I do not have access to the internals of JVM but would love to know how a private static void main(String[] args){} worked in older jvm's.
Later versions of JDK took care of the issue but just because it existed, proves one thing that the main method with String args quite does not work the way any other main method with int args works. [ August 29, 2006: Message edited by: Devesh H Rao ]