Back to Top

Sunday, 15 January 2012

JAVA : What if the static modifier is removed from the signature of the main method?

 Program compiles. But at runtime throws an error “NoSuchMethodError”.

3 Responses to “ JAVA : What if the static modifier is removed from the signature of the main method? ”

Anonymous said...
16 October 2012 at 17:27

you can write "static public void" or "public static void"...it doesn't matter. if you remove "static" from the main method signature you will need an instance of that class in order to execute it....for example:

if you want to just run a Java app in a batch environment MainClass.main(String[]) is called....which can happen because the main method is static and does not require an instance of an object. If main was not static you would have to execute that method like this:

MainClass mainClass = new MainClass();
mainClass.main(String[]);


Sandeep Reddy Katukuri said...
9 December 2015 at 22:36

Can you write one example sir?


Naviya Nair said...
24 October 2016 at 15:02

I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes

Java Training Institutes in Chennai Java Training in Chennai


Post a Comment

Popular Posts

Subscribe via Email
Subscribe Java Interview Questions via Email
All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar
blog links Web Directory Academics Blogs