English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Does JVM create an object of the Main class in Java?

As is well known, Java needsmain()To make a method executable in a public class, it needs to be set as static. The main reason for this requirement is to enable the JVM to callmain()method without creating an object. This simply means that the JVM will not create an object containing thismain()An object of the Main class. To prove this, we can make the Main class containing the main method abstract and the program still runs.

The following example shows the same content. Here, we have abstracted the main class.

Example

abstract public class Tester {
   public static void main(String args[]) {
      System.out.println("Main");
   }
}

Output Result

Main