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 functional interface in java?
Is special character in java?
How to print an arraylist in java?
Can two objects have same hashcode?
What is the difference between member variables initialization and assignment in a constructor?
Does constructor return any value?
What class allows you to read objects directly from a stream in java programming?
When a lot of changes are required in data, which one should be a preference to be used? String or stringbuffer?
What are class members by default?
Give an example of call be reference significance.
Is it possible to override the main method?
When do we use hashset over treeset?
Class c implements interface I containing method m1 and m2 declarations. Class c has provided implementation for method m2. Can I create an object of class c?
Can we overload the constructors?
What is the abstract class?