Command Line Arguments in Java are values passed to the main() method during program execution via the terminal or command prompt. They are stored in a String[] args array and allow dynamic input without modifying the code.
Time limit: 0
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
What is the index of the first command line argument?
Correct
Incorrect
Question 3 of 15
3. Question
What is printed when the program is executed as java Main Hello World?
public class Main { public static void main(String[] args) { System.out.println(args.length); } }
Correct
Incorrect
Question 4 of 15
4. Question
How to convert `args[0]` to an integer?
Correct
Incorrect
Question 5 of 15
5. Question
What happens if no arguments are passed and `args[0]` is accessed?
Correct
Incorrect
Question 6 of 15
6. Question
Can Java main method be written without arguments?
Correct
Incorrect
Question 7 of 15
7. Question
What is the default value of `args.length` when no arguments are passed?
Correct
Incorrect
Question 8 of 15
8. Question
How are command line arguments separated?
Correct
Incorrect
Question 9 of 15
9. Question
What will be the output of this code when run with `java App 4 5`?
public class App { public static void main(String[] args) { int sum = Integer.parseInt(args[0]) + Integer.parseInt(args[1]); System.out.println(sum); } }
Correct
Incorrect
Question 10 of 15
10. Question
Which exception is thrown when you access an invalid index in `args[]`?**
Correct
Incorrect
Question 11 of 15
11. Question
Can we pass arguments with spaces to Java programs?
Correct
Incorrect
Question 12 of 15
12. Question
Can the name of the `args` parameter be changed?
Correct
Incorrect
Question 13 of 15
13. Question
Which of the following is true about `args[]` in Java?
Correct
Incorrect
Question 14 of 15
14. Question
What is the purpose of command line arguments in Java?
Correct
Incorrect
Question 15 of 15
15. Question
If you run `java Test a b c`, what does `args[2]` contain?
Correct
Incorrect
Summary
This quiz covers command line syntax, argument parsing, runtime behavior, and exceptions related to Java’s `String[] args`. A must-practice for beginners and those preparing for coding interviews.
At QuizOrbit, our team specializes in fun, informative quizzes across topics like general knowledge, technology, and entertainment. Boost your knowledge with our expert-designed quizzes.