File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static modifier doubt 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 "static modifier doubt" Watch "static modifier doubt" New topic
Author

static modifier doubt

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383



The above code is given in chapter 2, page no:147. It gives input a a a. But I got runtime exception:Exception in thread "main" java.lang.NoSuchMethodError: main

Can anyone explain?


SCJP-1.5<br />SCWCD-1.4
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
You would have had both the classes defined in the same java file named StaticTest.java.Here in StaticTest.java has one public class StaticTest and one default class Static. After compilation two class files will be generated StaticTest.class and Static.class.
And now you would have run the below cmd
java StaticTest
This will result in the exception , because the class StaticTest does not have the main method.

Fix would be do swap the access modifiers of the classes and rename the class to Static.java
OR
java Static
will give the desired result. This will now look for the main() in Static.class and will find and execute it.

Thanks
Deepak


SCJP, SCWCD, SCBCD
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Thanks Deepak. I got it.
 
Don't get me started about those stupid light bulbs.
 
subject: static modifier doubt
 
Similar Threads
Static mmbers
Order of Static initialization Block,Instance initialization Block and Constructor....
When is a class loaded?
constructor and main whichone will execute first..
Static Main function VS Static user define function