Multiple choice technology programming languages

public class withoutmain{ static{ System.out.println("without the main method"); System.exit(0); } } What is the result of attempting to compile and run the program ?

  1. Compile failure

  2. sucessfully compiled, but through exception in run time.

  3. It runs sucessfuly and prints "without the main method"

  4. It runs sucessfuly, but No output.

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

This is nearly identical to question 141060. The class name is now 'withoutmain' instead of 'WithoutMain' (capital W), but the class is still public. Java allows public classes. The static block executes when the class loads, prints the message, and System.exit(0) terminates before main is required. The program compiles and runs successfully.