Advertisements
Advertisements
Question
Answer the following in brief. Give a reason/example wherever applicable.
What is the importance of main() in a program?
Give Reasons
Advertisements
Solution
- Triggers Execution: The operating system or runtime environment automatically looks for
main()to start running the application. Without it, a standalone program cannot execute. - Controls Program Flow: It acts as the central manager, invoking other functions and managing the lifecycle of the application.
- Example:
public class Car
{
//1.The engine starts here automatically
public static void main(String[]args)
{
System.out.println("Engine started.");
useBrakes();//2.
The main method activates other parts
}
public static void useBrakes()
{
System.out.println("Car stopped.");
}
}
shaalaa.com
Is there an error in this question or solution?
