Vidyalelo
Java Programming · Q44

Declaration and Access Control

Programming · Java Programming · question 44

Q44

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?

A.
It will fail to compile.
B.
Runtime error
C.
Compiles and runs with no output.
D.
Compiles and runs printing
Answer

Answer: Option D

Solution

Answer: Option D
Solution:

This will compile and print "Hello".
The entry point for a standalone java program is the main method of the class that is being run. The java run-time system will look for that method in class Test and find that it should have such a method. It does not matter whether it is defined in the class itself or is inherited from a parent class.