1.
Q) What is requirement
to provide “void” as return type to main() method ?
Ans):-
In java, JVM will create a thread to access
main() method called as “main Thread”, when main() thread will start
application execution at starting point of the main() method and main thread
will terminated application execution at ending point of main() method, because
of the reason, we have to start application logic at staring point of the
main() method and we have to terminate application logic at ending point of the
main() method, to achieve this required, we must not return any value from
main() method, for this, we must declare “void” as return type to main()
method.
Note:-
In java applications, if we declare main()
method without “void” return type then compiler will not rise any error, but
JVM will provide the following.
JAVA6: java.lang.NoSuchMEthodError: main
JAVA&: Error: main method must return a
value of type “void” is class test, please defined the main method as :
public
static void main(String[] args)
`````
Note
:-
The main intention to provide “main” as
name to the main() method is to show its importance in java applications.
No comments:
Post a Comment