• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing public static void main to public void static main , Is it Possible to execute the program?  RSS feed

 
Kasiraj Murugesa pandian
Greenhorn
Posts: 21
Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone ,
Is it possible to excute the program when the order of public static void main changes to public void static main () ? Although I have tried to execute the program by changing the order of void and static , i get the following errors and it says a '(' expected in it :

Errors

sample.java:4: error: <identifier> expected
public void static main(String args[])
^
sample.java:4: error: '(' expected
public void static main(String args[])
^
sample.java:4: error: invalid method declaration; return type required
public void static main(String args[])
^
3 errors


the Simple source code is as follows :
Source Code

I am just confused since this is the most frequently asked technical question in Aptitude and i have tried a lot to execute the program but i am still not able to get the exact solution for it . Hence It would be really great if you could come out with a detailed explanation stating how this can be sorted out.

Thanks a Lot in Advance


Regards,
Kasiraj M
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can't change the signature of main method, if you are doing so JVM would consider that method as a method.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void static main(String[] args) is not a valid method declaration - according to the rules of the Java programming language, the return type (void) must come after modifiers such as static. If you want to know the exact rules, see section 8.4 of the Java Language Specification.

So no, you cannot execute the program when you do this, because you cannot even compile it if you write it like that - it's not valid Java.

Kasiraj Murugesa pandian wrote:I am just confused since this is the most frequently asked technical question in Aptitude and i have tried a lot to execute the program but i am still not able to get the exact solution for it.

Really, is this a most frequently asked technical question? Strange.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:
Kasiraj Murugesa pandian wrote:I am just confused since this is the most frequently asked technical question in Aptitude and i have tried a lot to execute the program but i am still not able to get the exact solution for it.

Really, is this a most frequently asked technical question? Strange.


Indeed. I've never seen this question before, and I can't imagine why it would ever be asked. Knowing the answer is of no value whatsoever.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kasiraj Murugesa pandian wrote:i have tried a lot to execute the program but i am still not able to get the exact solution for itM

But that means you did get the solution. You knew it wouldn't work. Trust the compiler.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!