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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- In Java, Can we call the main() method of a class from another class?
- Main thread in Java
- GFact 48 | Overloading main() in Java
- Valid variants of main() in Java
- Is main method compulsory in Java?
- What are the main differences between the Java platform and other platforms?
- Static Block and main() method in Java
- How to overload and override main method in Java
- Replacing 'public' with 'private' in "main" in Java
- Object class in Java
- Main App Implements Runnable | Concurrent Programming Approach 2
- Java | How to create your own Helper Class?
- How to create a Class in JShell of Java 9
- How to create Immutable class in Java?
- Java Object Creation of Inherited Class
- Understanding public static void main(String args) in Java
- Execute main() multiple times without using any other function or condition or recursion in Java
- Inner Class And Anonymous Inner Class that Implements Runnable | Concurrent Programming Approach 3
- How to create a Java HashMap of user defined class type?
- Implement Septet Class from Sextet Class in Java using JavaTuples
Improved By : YashGovindani