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
What is the hashcode () and equals () used for?
Whats the difference between notify() and notifyall()?
What is the difference between public, private, protected, and friend access?
What's the purpose of static methods and static variables?
Can we have a method name same as class name in java?
Write a regular expression to validate a password. A password must start with an alphabet and followed by alphanumeric characters; its length must be in between 8 to 20.
What is floor in java?
Define the term string pool?
How do you use substring in java?
how can you catch multiple exceptions in java?
Write a program in java to create a doubly linked list containing n nodes.
How to print an arraylist in java?
Explain about wait() method?
What is Java Reflection API? Why it’s so important to have?
Difference between comparator and comparable in java?