Java OCA OCP Practice Question 2355

Question

Given the following definition of the class Main,

public class Main { 
    public static void main(String[] args) { 
        System.out.println(args[1]+":"+ args[2]+":"+ args[3]); 
    } 
} 

what is the output of Main, if it is executed using the following command?

java Main one two three four 
  • a one:two:three
  • b Main:one:two
  • c java:Main:one
  • d two:three:four


d

Note

The command-line arguments passed to the main method of a class do not contain the word Java and the name of the class.

Because the position of an array is zero-based, the method argument is assigned the following values:.

args[0] -> one 
args[1] -> two 
args[2] -> three 
args[3] -> four 

The class prints two:three:four.




PreviousNext

Related