gs gs128 Java Classes Methods - Java Command Line Arguments - Quiz No.1
gs gs128 Java Quiz
This quiz belongs to book/course code gs gs128 Java of gs organization. We have 136 quizzes available related to the book/course Java. This quiz has a total of 20 multiple choice questions (MCQs) to prepare and belongs to topic Java Classes Methods. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
Question 1: Which of this method is given parameter via command line arguments?
main()
recursive() method
Any method
System defined methods
Question 2: Which of these data types is used to store command line arguments?
Array
Stack
String
Integer
Question 3: How many arguments can be passed to main()?
Infinite
Only 1
System Dependent
None of the mentioned
Question 4: Which of these is a correct statement about args in the following line of code?
public static void main(String args[])
args is a String
args is a Character
args is an array of String
args in an array of Character
Question 5: Can command line arguments be converted into int automatically if required?
Yes
No
Compiler Dependent
Only ASCII characters can be converted
Question 8: What will be the output of the following Java program, Command line execution is done as – java Output “This is a command Line”?
class Output { public static void main(String args[]) { for (String arg : args) { System.out.print(arg); } } }
This
java Output This is a command Line
This is a command Line
Compilation Error
Question 11: What will be the output of the following Java snippet, if attempted to compile and run this code with command line argument “java abc Rakesh Sharma”?
public class abc { int a=2000; public static void main(String argv[]) { System.out.println(argv[1]+" :-Please pay Rs."+a); } }
Compile time error
Compilation but runtime error
Compilation and output Rakesh :-Please pay Rs.2000
Compilation and output Sharma :-Please pay Rs.2000
Question 12: What will be the output of the following Java snippet, if attempted to compile and execute?
class abc { public static void main(String args[]) { if(args.length>0) System.out.println(args.length); } }
The snippet compiles, runs and prints 0
The snippet compiles, runs and prints 1
The snippet does not compile
The snippet compiles and runs but does not print anything
Question 14: What will be the output of the following Java code snippet running with "java demo I write java code"?
public class demo { public static void main(String args[]) { System.out.println(args[0]+""+args[args.length-1]); } }
The snippet compiles, runs and prints "java demo"
The snippet compiles, runs and prints "java code"
The snippet compiles, runs and prints "demo code"
The snippet compiles, runs and prints "I code"
Question 15: What will be the output of the following Java snippet, if compiled and executed with command line "hello there"?
public class abc { String[] xyz; public static void main(String argv[]) { xyz=argv; } public void runMethod() { System.out.println(argv[1]); } }
Compile time error
Output would be "hello"
Output would be "there"
Output would be "hello there"
Question 16: How do we pass command line argument in Eclipse?
Arguments tab
Variable tab
Cannot pass command line argument in eclipse
Environment variable tab
Question 17: Which class allows parsing of command line arguments?
Args
JCommander
Command Line
Input
Question 18: Which annotation is used to represent command line input and assigned to correct data type?
@Input
@Variable
@Command Line
@Parameter
Question 20: What is the use of @syntax?
Allows multiple parameters to be passed
Allows one to put all your options into a file and pass this file as a parameter
Allows one to pass only one parameter
Allows one to pass one file containing only one parameter