Sunday, 15 January 2012
JAVA: What if the main method is declared as private?
Do you like this Article?
The program compiles properly but at run-time it will give "Main method not public." message
Subscribe to:
Post Comments
(
Atom
)
Popular Posts
-
public - public means everyone can access it.That means it's in global scope. As, main method is called by JVM [ Java Virtual Machine...
-
throw is used to throw an exception in a program, explicitly . Whereas, throws is included in the method's declaration part, wi...
-
Singleton in one of the most popular yet controversial design pattern, in the world of object oriented programming. It's one of t...
-
Web Container / Servlet Container / Servlet Engine : In J2EE Architecture , a web container (also known as servlet container or ser...
-
Program compiles. But at runtime throws an error “NoSuchMethodError”.
-
Vector : It's synchronized. It's slower than ArrayList. It's generally used in ...
-
doGet(): protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, java.io.IOException – is a met...
-
In Java Programming Language , we must declare a variable name and type, before using it. The data type of a variable defines the th...
4 Responses to “ JAVA: What if the main method is declared as private? ”
6 June 2012 at 07:51
what happens main method write like this.... public void main()
11 June 2012 at 18:15
it will compile but we get the error while executing the code with an error as "NoSuchMethodError".because the JVM calls the main() by the class name with static keyword.i.e.,
Note:With static keyword we can call the any method by using class name itself,no need of any object creation and calling the respective method.
In the same way the JVM calls the main() with class name by using the static keyword.So,static is mandatory to write.
14 September 2012 at 23:47
No compile error.
But, main method will not be accessible by JVM.
26 June 2013 at 04:00
Run time error
Post a Comment