Multiple choice technology programming languages

18 You have a public class called myclass with the main method defined as follows public static void main(String parm[]){ System.out.println(parm[0]); } If you attempt to compile the class and run the program as follows java myclass hello What will happen?

  1. a. Compile time error, main is not correctly defined

  2. b. Run time error, main is not correctly defined

  3. c. Compilation and output of java

  4. d. Compilation and output of hello

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

The main method signature is correctly defined (static void, String array parameter). When running 'java myclass hello', 'hello' becomes args[0]. The program prints parm[0] which is 'hello'. The parameter name 'parm' is unusual but legal - Java doesn't enforce specific parameter names for main.

AI explanation

The main method signature public static void main(String parm[]) is valid, so the class compiles cleanly. When run as java myclass hello, the JVM passes hello as parm[0], so the program prints hello. The class name after java is just which class to run, not an argument, so it never gets printed.