Explantion and Importance of main() method in java programming
Explanation of main() method in java programming
The entry point of executing a Java program is the main method.We know that Java programs work in oops concepts.Java programs are treated as objects and classes.If there is more than one class in a program,The program should be named using the class containing the main() method,because main() method is the entry point of Java program.
java main method explanation
Syntax of main method
public static void main (String args[]){
}
Importance of main function in java programming
Here the public is an access modifier.There are different modifiers available in java If a function is declared public, the scope of the function is the entire program.Static keyword is the keyword where we can directly access the method without object.If the method is static, then such method can be accessed directly.Here void is a return type.Every method has a return type.When writing a method, the return type is compulsory. The return type will change based on the program logic.Here main is method name Java programming supports the command line arguments.In the command line arguments we can give the inputs.Here String is a predefined class in java and args is the array name.It is the user defined name.
Java basic interview questions for freshers
1 purpose of main method in java?
A: Main is method,its the entry point for executing a java program
The main method can contain code to execute or call other methods,
and it can be placed in any class that's part of a program.
2 why main method is public in java?
A: If a function is declared public, the scope of the function is the entire program.
without object creation, to access directly
3 why main method is static in java?
If a function is declared static its can be accessed directly.
why main method is void in java?
A: Every method has a return type.Return type must be written in Java program.
Return type is not always void. It can change according to program logic.
Comments
Post a Comment