Q: Why is the main method declared as static in Java?
-
A
It allows the method to be called without creating an instance of the class.
-
B
It ensures that the main method is executed first when the program starts.
-
C
It enables the main method to access static variables and methods directly.
-
D
All of the above.
D
Answer:
D
Explanation:
The main method in Java is declared as static so that it can be called without creating an instance of the class. This is because the main method is the entry point of the program and needs to be executed first when the program starts. Additionally, the main method is declared as static so that it can access static variables and methods directly without the need to create an instance of the class.
Related Topic:
Share Above MCQ