jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static modifier doubt" Watch "static modifier doubt" New topic

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
java Static
will give the desired result. This will now look for the main() in Static.class and will find and execute it.


dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Thanks Deepak. I got it.
Have you checked out Aspose?
subject: static modifier doubt
It's not a secret anymore!