Is it possible to have the main method accept an argument other than a string array? For example, can we have a method like main(Animals[]args){/*code*/}? If not, then why?
Is it possible to have the main method accept an argument other than a
Share
No – the entry point is always the method with the header
public static void main(String[] args)(i.e. the JVM invokes this particular method). You can certainly define a methodbut it would not be executed directly upon running the program.
EDIT: The reason the
mainmethod specifically has a string-array argument is because this array will contain the command-line arguments when the program is run. Intuitively, these should be strings (and certainly notAnimals, for example).