Advertisements
Advertisements
प्रश्न
Answer the following in brief. Give a reason/example wherever applicable.
What is the importance of main() in a program?
कारण बताइए
Advertisements
उत्तर
- 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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
