Does JVM creates object of Main class in Java?


As we know that Java needs main() method to be static in the public class to make it executable. The prime reason for this requirement is to make JVM enable to call the main() method without creating an object. That simply means that JVM does not create the object of the Main class which contains the main() method. To justify the same, we can make the Main class containing the main method as abstract and program still runs.

Following example showcases the same. Here we have made the main class abstract.

Example

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

Output

Main

Updated on: 26-Jun-2020

348 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements