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


Please Help Members By Posting Answers For Below Questions

What is instance synchronization?

561


Can arraylist hold different types java?

497


What is arraylist e in java?

528


What is not thread safe?

504


What are peerless components in java programming?

591






How do you allocate memory to object?

532


What is a map in java?

560


What is static data type in java?

555


How do you override a variable in java?

539


What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?

524


Why string objects are immutable in java?

572


Tell me about different OOPS concepts.

601


What is difference between hashset and hashmap in java?

472


Explain about oops concepts.

640


whar are the draw backs of programming lang step by step in Clang and next in C++ and next and in Java nad in .Net

1667