Multiple choice technology programming languages

class A { public static void main(String args[]) { System.out.println(args.length); } } what is the output if the code is run using command line invocation java A

  1. NullPointerException

  2. Compilation fails

  3. 0

  4. 1

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

args is the command-line arguments array. When running 'java A' with no arguments, args is an empty array (length 0), not null. The code correctly accesses args.length without null checks. This tests understanding that args.length is 0 for no arguments, and that an empty array is not null.