| Author |
java
|
Sonu Nigam
Greenhorn
Joined: Jun 22, 2008
Posts: 2
|
|
|
why we use static in public static void main(string arr[])?
|
 |
Norm Radder
Ranch Hand
Joined: Aug 10, 2005
Posts: 681
|
|
When the java command starts a program, it needs a FIXed way to call it. By making main() static, it can call main() and let main() do what is needed to instantiate the class and get it started.
|
 |
J New
Greenhorn
Joined: Jun 27, 2008
Posts: 5
|
|
.. because the main{String []args)method has to be called by OS.So in order to make it possible for OS to access it without creating the instance of the class, containing the main(String []args)method,it is declared static.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56151
|
|
"J new", please check your private messages for a final important administrative matter. [ June 27, 2008: Message edited by: Bear Bibeault ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
siddharth, welcome to JavaRanch. Please use a meaningful subject line when you post a question, instead of a title like "java". A better title would have been, for example: "Why is main() static?". To answer your question: It's really just a design decision by the people who invented the Java language. By making main() static, the JVM doesn't have to instantiate the class that the method is in to be able to call it - which makes starting a program simpler. [ June 27, 2008: Message edited by: Jesper Young ]
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: java
|
|
|