Results 1 to 6 of 6
- 10-06-2008, 12:09 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 31
- Rep Power
- 0
[SOLVED] Why main() in java is declared as public static void main?
Why main() in java is declared as public static void main?
This question was asked to my friend in her interview.
I am looking for a well organized answer on this question, which can be used in an interview, can someone help.Live life king size
[Lucene]
- 10-06-2008, 12:15 AM #2
Member
- Join Date
- Oct 2008
- Location
- US
- Posts
- 58
- Rep Power
- 0
Public - main method is called by JVM to run the method which is outside the scope of project therefore the access specifier has to be public to permit call from anywhere outside the application
static - When the JVM makes are call to the main method there is not object existing for the class being called therefore it has to have static method to allow invocation from class.
void - Java is platform independant language therefore if it will return some value then the value may mean different to different platforms so unlike C it can not assume a behavior of returning value to the operating system.
Read more about Java Fundamental Questions : Java Fundamental Questions
____________________________________________
Software WikiHave fun....
JAVA FAQs
- 10-06-2008, 12:16 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 68
- Rep Power
- 0
I would advise to Search First, but in this case the search words form a bit of a problem: every post with code with a main method will turn up in the results.
Still, this question has been asked before, so perhaps if you can find the right words to sort on you might get a result with the answer.
____________________________________________
Cooking is FunCheers,
Eat Healthy Stay Fit
- 10-06-2008, 12:18 AM #4
Member
- Join Date
- Oct 2008
- Posts
- 68
- Rep Power
- 0
The forum has lots of similar questions asked before, you are not the first one to face this. So make sure that you are utilizing the forums potential to fullest.
____________________________________________
Priya,
Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | DalCheers,
Eat Healthy Stay Fit
- 10-06-2008, 12:19 AM #5
Well to do that, we may have to have some idea what book the interviewer has read and believes. Basically, it is because someone decided to do it that way but that will not go over in an interview. My suggestion is to do direct research on the JSR's and if there is no statement on the matter in the Java Specification - then that is the true answer but additional work would be needful to have several answers ready, trying to get them all out before interviewer plays one-ups-man-ship on would be coder.
No matter how you word your reply, there will be some snip-nosed replies from people who fabricated interview questions rather than writing code.
6-months filppin burgers will make such questions nubile in nature.
{ message edit: I go with kzvi.kzvi.1 - as this appears to be the correct answer }Last edited by Nicholas Jordan; 10-06-2008 at 12:22 AM. Reason: correct answer already posted
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 10-06-2008, 01:11 AM #6
Member
- Join Date
- Oct 2008
- Posts
- 31
- Rep Power
- 0
Similar Threads
-
Class is public, should be declared in a file
By goldhouse in forum New To JavaReplies: 7Last Post: 05-10-2012, 10:17 AM -
The different of static void,protected,and void in methods?
By Winarto in forum New To JavaReplies: 5Last Post: 01-25-2008, 12:53 AM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 08:10 AM -
exception in thred main java.lang.nosuchmethoderror: main
By fernando in forum Java AppletsReplies: 1Last Post: 08-06-2007, 10:11 AM
Bookmarks