Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes RunTime error with main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "RunTime error with main" Watch "RunTime error with main" New topic

RunTime error with main

Binu K Idicula
Ranch Hand

Joined: Jul 11, 2002
Posts: 99
My doubt is related to main methid. Already I saw "main method should be public static" , but if my intention is to give a method called main, so that other object can call this , any runtime error as quoted ??
class test1{
final static void main(String args[]){
System.out.println(" from test 1");
class test2{
final static void main(String args[]){
System.out.println(" from test 2");
class test3{
public static void main(String args[]){
test1.main(new String[]{"A"});
test2.main(new String[]{"B"});
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
The compiler will not object to any declaration of a method named main as long as the declaration is a legal method declaration. However, the JVM places restrictions on a main method that is called from the command line. In your example, you are free to call test3.main from the command line, but you may not call test1.main or test2.main from the command line.
Of course, using the name "main" for a method that is not called from the command line could confuse readers.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">Try my mock exam.</a>
yogesh sood
Ranch Hand

Joined: Aug 31, 2000
Posts: 108
hi there
There is No runtime error there is no problem with this code neither at Runtime nor at compile time it runs smooooothly .
Although its a bit confusing at first look

If its green its biology if its stinkks its chemistry if it has numbers it is Maths and if it doesn't work its TECHNOLOGY
Binu K Idicula
Ranch Hand

Joined: Jul 11, 2002
Posts: 99
yeah... I was also telling there is no runtime exception when we use main not as command line methd. But the discussion was on main method called from command line . I asked about main methods not called from command line.
Ofcourse there is no runtime error in the code specified. Sorry if it mislead
I agree. Here's the link:
subject: RunTime error with main
Similar Threads
could someone help?
does static methods inherit ? what about private ?
instanceof Q? for SCJP
Java Rule Round-Up