Search code examples
javaprogram-entry-pointjava-10

Initialization of Main() in java and seeking alternative code


I am given a following partial Java code:

public static void main(String[] args) {
  var main = new Main();
  main.start();
}

I don't understand the initializing in Line 2 (Main()).

Also, what is the datatype of Main()? Suppose, I don't want to use 'var' keyword, then what should I use?

If there is any alternative code for this, please let me know.


Solution

  • I don't understand the initializing in Line 2 (Main())

    You're initializing an object of type Main, in order to call the instance method start()

    The alternative is to replace var with Main

    Or simply new Main().start();