Does JVM creates object of Main class in Java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Updated on 26-Jun-2020 07:40:55

Advertisements