Search code examples
javaprogram-entry-point

When is java main method called?


  1. I have a class(1) having some constructors(arg and no args). In another class(2) an object of Class 1 is created using new constructor(). So will main method get called in this case?

  2. Ideally when is main method called in any class?


Solution

  • main is a static method, the entry point for the program, and is called once (unless you explicitly call it), when the program starts, not for each object initialization.