Question: Explain PSVM() [Public Static Void Main()] in Java.
Answer:
This question is asked from a differnet persctive. Person asking this question is looking for deep java concepts.
If answer in your mind is something like this, "Public is used so that main() will be accssible everywhere, static is used so that no need to create object, void is because its not returning anything"
Then you are rejected stright-away.
Actual answer to this question is:
1. Public:
- It is access modifier.
- It is kept public since JVM should be able to access the main() from outside the package / project.
2. Static:
- It is kept static so that JVM should be able to call the main() without creating an object. (Why to waste memory just to start something).
3. Void:
- It is void since returning something from the main() is not something we intend to do.
- However, you can return something indeed [from the main()].
4. Main:
- It is a pre-specified word that the JVM searched for.
- This name can be changed as well.