Main method can be created in the below ways:
public static void main(String[] args) {}
public static void main(String molecules[]) {}
static public void main(String[] gadgets) {}
static public void main(String spaces[]) {}
public static void main(String ... countries) {} //String three dots(...) args/any variable name
static public void main(String ... data) {}
1. public and static can appear in any order in main function
2. [] can appear before or after the variable name
3. as of java 5 [] can be replaced with ...(three dots), but it should appear between String and the variable. 9This feature is called var-args and has been added in java 5.0. You can use var-args in any method or constructor. It must be the last arguments. you can pass only one var-arg argument. var-arg argument is considered as a array. so a class cannot have 2 methods one havin g a array of String and another having only var-args of String)
4. the most important is that argument's name can be anything ie instead of args we can name it with our own name.
i think these are the ways main method can be written.
Build Your Own Test Framework
-
[image: Build Your Own Test Framework]
Learn to write better automated tests that will dramatically increase your
productivity and have fun while doing so...
2 hours ago
No comments:
Post a Comment
I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.