Multiple choice technology programming languages

public class Counter { public static void main(String[] args) { int numArgs = /* insert code here */; } } and the command line: java Counter one fred 42 Which code, inserted at line 3, captures the number of arguments passed into the program?

  1. args.count

  2. args.length

  3. args.count()

  4. args.length()

  5. args.getLength()

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Java, the args parameter is an array. Arrays have a length property (not a method), so args.length returns the number of command-line arguments. The other options use incorrect syntax like count(), getLength(), or treating length as a method.