Multiple choice technology programming languages

You have the following code in a file called Test.java class Base{ public static void main(String[] args){ System.out.println("Hello"); } } public class Test extends Base{} What will happen if you try to compile and run this?

  1. It will fail to compile.

  2. Runtime error

  3. Compiles and runs with no output.

  4. Compiles and runs printing "Hello"

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

The code compiles and runs successfully because the main() method is inherited from the Base class. Even though Test extends Base, static methods are not inherited in the traditional sense - they belong to the class where they're defined. However, when you run 'java Test', it executes Base.main() which prints "Hello".