Consider following program.
Does JVM create an object of class Main?
The answer is “No”. We have studied that the reason for main() static in Java is to make sure that the main() can be called without any instance. To justify the same, we can see that the following program compiles and runs fine.
Since we can’t create object of abstract classes in Java, it is guaranteed that object of class with main() is not created by JVM.
This article is contributed by Narendra Koli. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Is main method compulsory in Java?
- Myth about the file name and class name in Java
- How is Java platform independent?
- How JVM Works – JVM Architecture?
- Abstract Classes in Java
- HashSet vs TreeSet in Java
- ShortBuffer allocate() method in Java With Examples
- IntBuffer duplicate() method in Java with Examples
- ShortBuffer compact() method in Java With Examples
- LongBuffer equals() method in Java