Does JVM creates an object of the Main class?

Java Programming Java8Object Oriented Programming

As we know that Java needs main() method to be static in the public class to make it executable. Prime reason for this requirement it to make JVM enable to call the main() method without creating an object. That simply means that JVM does not create the object of 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.

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

Output

Main
raja
Updated on 21-Jun-2020 13:01:16

Advertisements