-4

If MyProg.java were compiled as an application and then run from the command line as:

java MyProg I like tests

what would be the value of args[ 1 ] inside the main( ) method?

  1. MyProg
  2. "I"
  3. "like"
  4. 3
  5. 4
  6. null until a value is assigned
Zsw
  • 3,920
  • 4
  • 29
  • 43
prasad
  • 63
  • 2
  • 9
  • @Satya No need, mate, I can read minds. Just gimme a few minutes. – async Sep 23 '15 at 18:10
  • It is not the code I just saw the same question but couldnt understand it. – prasad Sep 23 '15 at 18:10
  • 1
    possible duplicate of [What is "String args\[\]"? parameter in main method Java](http://stackoverflow.com/questions/890966/what-is-string-args-parameter-in-main-method-java) – childofsoong Sep 23 '15 at 18:19

3 Answers3

1

Arguments come in as an array, which are 0-based.

java myProgram a b c

means

args[0] == 'a'
args[1] == 'b'
args[2] == 'c'
ergonaut
  • 6,929
  • 1
  • 17
  • 47
0

It'd be a String, "like". The class file being run isn't included in the arguments array.

Chris Dennett
  • 22,412
  • 8
  • 58
  • 84
0
class CommandLine 
{
    public static void main(String args[])
    {
        System.out.println(args[0]);
        System.out.println(args[1]);
    }
}

For Running : java CommandLine aaa bbb

Output -

 aaa
 bbb

Here aaa is treated as first and bbb is treated as second argument for command line.

ABHISHEK RANA
  • 333
  • 3
  • 7