What is the argument type of a program's main() method

A program's main() method takes an argument of the String[] type.

Showing Answers 1 - 2 of 2 Answers

vegetto

  • Jun 16th, 2008
 

you write public static void main(String args[])

so the argument type isstring and whatever input you give as

java abs "asd" 1

then all the 3 arguments are stored int he corresponding string format in the args array and if you write
 
for(int i=0;i<args.length;i++)
{  System.out.println(args[i]);}
 the it prints:
abs
"asd"
1

  Was this answer useful?  Yes

In C and C++, main() function can take the arguments with type int and char as shown below.
void main(int argc,char *argv)

In Java main() function take the arguments in String type and the above type is also allowed.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.