In Java why we write public static void main(String args[])
why not main()?
Answer Posted / anjani kumar jha
Use of Public-----There is always only one main class that
is one file having only one main file. Since that main file
is used anywhere means might be in another package so there
is a public use of keyword that is public keyword is
required for main function
Static:-----Since compiler in java always look the main
function and when compiler always calls the main so main
class is loaded in first time call for that static keyword
is used.
you can use
1)public void main(String args[])
it compiles file but wont run\
2) void main(String args[])
it compiles file but wont run
3)void main(String args[])
it compiles file but wont run
| Is This Answer Correct ? | 87 Yes | 37 No |
Post New Answer View All Answers
Difference between static and dynamic class loading.
How do you convert string to int in java?
Difference between static synchronization vs. Instance synchronization?
What is a variable analysis?
What do you mean by order of precedence and associativity?
Can a class be declared as protected?
What is difference between arraylist and list in java?
What is a blocking method in Java?
What is difference between final and immutable?
Why pass by reference is not possible in java?
What is the latest version of java?
What is anagram word?
What is the method in java?
What is the main use of java?
What is autoboxing in java?