- Is the static void main class the entrance to your program regardless of which class calls it… Or is it just the entrance method for that specific class…
-
How on earth does this work:
public class init{ public static void main(String[] args){ new init(); } public init(){ System.out.print("hi"); } }I dont understand the way the program creates an instance of itself… why cant you just do this?
public class init{ public static void main(String[] args){ start(); } public static void start(){ System.out.print("hi"); } } -
What on earth does static do versus simple public.
Is the static void main class the entrance to your program regardless of which
Share
It’s the method to say the JVM where the program can start, very similar to
mainfunction in C/C++ programs. If you have more than 1 class with this method, then you should tell the JVM which class will be the program entrance.statickeyword means the methods/variables belong to the class, simply private/protected/public/default means the methods/variables belong to the class instance (the objects).You’re creating an instance of the
initclass. There’s nothing wrong doing that in Java code. In the class constructor, the program will print aHiword in the console.