Command Line Arguments(Computer Science > Java Program ) Questions and Answers

Question 1.


What is the output of this program, Command line execution is done as -



"java Output command Line 10 A b 4 N"?


class Output {
public static void main(String args[]) {
System.out.print("args[6]");
}
}
  1.    java
  2.    10
  3.    b
  4.    N
Explanation:-
Answer: Option D. -> N

None.
Output:
$ javac Output.javac
java Output command Line 10 A b 4 N
N



Question 2.


What is the output of this program, Command line execution is done as -



"java Output command Line 10 A b 4 N"?


class Output {
public static void main(String args[]) {
System.out.print("(int)args[2] * 2");
}
}
  1.    java
  2.    10
  3.    20
  4.    b
Explanation:-
Answer: Option C. -> 20

None.
Output:
$ javac Output.javac
java Output command Line 10 A b 4 N
20



Question 3.


What is the output of this program, Command line execution is done as -



"java Output This is a command Line"?


class Output {
public static void main(String args[]) {
System.out.print("args");
}
}
  1.    This
  2.    java Output This is a command Line
  3.    This is a command Line
  4.    Compilation Error
Explanation:-
Answer: Option C. -> This is a command Line

None.
Output:
$ javac Output.javac
java Output This is a command Line
This is a command Line



Question 4.


What is the output of this program, Command line exceution is done as -



"java Output This is a command Line"?


class Output {
public static void main(String args[]) {
System.out.print("args[3]");
}
}
  1.    java
  2.    is
  3.    This
  4.    command
Explanation:-
Answer: Option D. -> command

None.
Output:
$ javac Output.javac
java Output This is a command Line
command



Question 5.


What is the output of this program, Command line execution is done as -



"java Output This is a command Line"?


class Output {
public static void main(String args[]) {
System.out.print("args[0]");
}
}
  1.    java
  2.    Oupput
  3.    This
  4.    is
Explanation:-
Answer: Option D. -> is

None.
Output:
$ javac Output.javac
java Output This is a command Line
This



Question 6.

Can command line arguments be converted into int automatically if required?


  1.    Yes
  2.    No
  3.    Compiler Dependent
  4.    Only ASCII characters can be converted.
Explanation:-
Answer: Option B. -> No

All command Line arguments are passed as a string. We must convert numerical 

value to their internal forms manually.



Question 7.

How many arguments can be passed to main()?


  1.    Infinite
  2.    Only 1
  3.    System Dependent
  4.    None of the mentioned
Explanation:-
Answer: Option A. -> Infinite

None.



Question 8.

Which of these is a correct statement about args in this line of code?
public static viod main(String args[])


  1.    args is a String.
  2.    args is a Character.
  3.    args is an array of String.
  4.    args in an array of Character.
Explanation:-
Answer: Option C. -> args is an array of String.

args in an array of String.



Question 9.

Which of these data types is used to store command line arguments?


  1.    Array
  2.    Stack
  3.    String
  4.    Integer
Explanation:-
Answer: Option C. -> String

None.



Question 10.

Which of these method is given parameter via command line arguments?


  1.    main().
  2.    recursive() method.
  3.    Any method.
  4.    System defined methods.
Explanation:-
Answer: Option A. -> main().

Only main() method can be given parameters via using command line arguments.